

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>dcase_framework.learners &mdash; DCASE2017 Baseline 1.0 documentation</title>
  

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  
    <link rel="stylesheet" href="../../_static/theme_overrides.css" type="text/css" />
  

  
        <link rel="index" title="Index"
              href="../../genindex.html"/>
        <link rel="search" title="Search" href="../../search.html"/>
    <link rel="top" title="DCASE2017 Baseline 1.0 documentation" href="../../index.html"/>
        <link rel="up" title="Module code" href="../index.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> DCASE2017 Baseline
          

          
            
            <img src="../../_static/dcase2017_baseline.png" class="logo" />
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Baseline system</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../system_description.html">System description</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../system_description.html#mlp-based-system-dcase2017-baseline">MLP based system, DCASE2017 baseline</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../system_description.html#gmm-based-approach">GMM based approach</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../system_description.html#processing-blocks">Processing blocks</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../applications.html">Applications</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../applications.html#task1-acoustic-scene-classification"> Acoustic scene classification</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../applications.html#results">Results</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../applications.html#task2-detection-of-rare-sound-events"> Detection of rare sound events</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../applications.html#id2">Results</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../applications.html#task3-sound-event-detection-in-real-life-audio"> Sound event detection in real life audio</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../applications.html#id3">Results</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../usage_tutorial.html">Usage</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../usage_tutorial.html#application-arguments">Application arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../usage_tutorial.html#basic-usage">Basic usage</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../parameterization.html">Parameterization</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../parameterization.html#parameter-overwriting">Parameter overwriting</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../parameterization.html#parameter-file">Parameter file</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../parameterization.html#parameter-hash">Parameter hash</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../parameterization.html#parameter-sections">Parameter sections</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#flow">Flow</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#general">General</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#path">Path</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#dataset">Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#feature-extractor">Feature extractor</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#feature-stacker">Feature stacker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#feature-normalizer">Feature normalizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#feature-aggregator">Feature aggregator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#learner">Learner</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#recognizer">Recognizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#evaluator">Evaluator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../parameterization.html#logging">Logging</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../reproducibility.html">Reproducibility</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../reproducibility.html#blas-libraries">BLAS libraries</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../reproducibility.html#intel-math-kernel">Intel Math Kernel</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../reproducibility.html#running-the-baseline-system">Running the baseline system</a></li>
</ul>
</li>
</ul>
<p class="caption"><span class="caption-text">DCASE Framework</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../framework.html">Introduction</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../framework.html#training-process">Training process</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../framework.html#testing-process">Testing process</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../extending_framework.html">Extending the framework</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../extending_framework.html#adding-datasets">Adding datasets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../extending_framework.html#adding-features">Adding features</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../extending_framework.html#addinng-learners">Addinng learners</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../extending_framework.html#extending-applicationcore">Extending ApplicationCore</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../application_core.html">Application core</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../application_core.html#acousticsceneclassificationappcore">AcousticSceneClassificationAppCore</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.html">dcase_framework.application_core.AcousticSceneClassificationAppCore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.show_dataset_list.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.show_dataset_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.show_parameters.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.show_parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.initialize.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.initialize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.feature_extraction.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.feature_extraction</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.feature_normalization.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.feature_normalization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.system_training.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.system_training</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.system_testing.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.system_testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AcousticSceneClassificationAppCore.system_evaluation.html">dcase_framework.application_core.AcousticSceneClassificationAppCore.system_evaluation</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../application_core.html#soundeventappcore">SoundEventAppCore</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.html">dcase_framework.application_core.SoundEventAppCore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.show_dataset_list.html">dcase_framework.application_core.SoundEventAppCore.show_dataset_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.show_parameters.html">dcase_framework.application_core.SoundEventAppCore.show_parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.initialize.html">dcase_framework.application_core.SoundEventAppCore.initialize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.feature_extraction.html">dcase_framework.application_core.SoundEventAppCore.feature_extraction</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.feature_normalization.html">dcase_framework.application_core.SoundEventAppCore.feature_normalization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.system_training.html">dcase_framework.application_core.SoundEventAppCore.system_training</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.system_testing.html">dcase_framework.application_core.SoundEventAppCore.system_testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.SoundEventAppCore.system_evaluation.html">dcase_framework.application_core.SoundEventAppCore.system_evaluation</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../application_core.html#binarysoundeventappcore">BinarySoundEventAppCore</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.html">dcase_framework.application_core.BinarySoundEventAppCore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.show_dataset_list.html">dcase_framework.application_core.BinarySoundEventAppCore.show_dataset_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.show_parameters.html">dcase_framework.application_core.BinarySoundEventAppCore.show_parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.initialize.html">dcase_framework.application_core.BinarySoundEventAppCore.initialize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.feature_extraction.html">dcase_framework.application_core.BinarySoundEventAppCore.feature_extraction</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.feature_normalization.html">dcase_framework.application_core.BinarySoundEventAppCore.feature_normalization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.system_training.html">dcase_framework.application_core.BinarySoundEventAppCore.system_training</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.system_testing.html">dcase_framework.application_core.BinarySoundEventAppCore.system_testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.BinarySoundEventAppCore.system_evaluation.html">dcase_framework.application_core.BinarySoundEventAppCore.system_evaluation</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../application_core.html#appcore-base-class">AppCore &#8211; base class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.html">dcase_framework.application_core.AppCore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.show_dataset_list.html">dcase_framework.application_core.AppCore.show_dataset_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.show_parameters.html">dcase_framework.application_core.AppCore.show_parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.initialize.html">dcase_framework.application_core.AppCore.initialize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.feature_extraction.html">dcase_framework.application_core.AppCore.feature_extraction</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.feature_normalization.html">dcase_framework.application_core.AppCore.feature_normalization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.system_training.html">dcase_framework.application_core.AppCore.system_training</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.system_testing.html">dcase_framework.application_core.AppCore.system_testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.application_core.AppCore.system_evaluation.html">dcase_framework.application_core.AppCore.system_evaluation</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../parameters.html">Parameters</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../parameters.html#recipe">Recipe</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../parameters.html#paths-and-parameter-hash">Paths and parameter hash</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../parameters.html#parametercontainer">ParameterContainer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.html">dcase_framework.parameters.ParameterContainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.load.html">dcase_framework.parameters.ParameterContainer.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.save.html">dcase_framework.parameters.ParameterContainer.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.exists.html">dcase_framework.parameters.ParameterContainer.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.get_path.html">dcase_framework.parameters.ParameterContainer.get_path</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.show.html">dcase_framework.parameters.ParameterContainer.show</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.log.html">dcase_framework.parameters.ParameterContainer.log</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.override.html">dcase_framework.parameters.ParameterContainer.override</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.process.html">dcase_framework.parameters.ParameterContainer.process</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.process_method_parameters.html">dcase_framework.parameters.ParameterContainer.process_method_parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.parameters.ParameterContainer.get_hash.html">dcase_framework.parameters.ParameterContainer.get_hash</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../files.html">Files</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#audiofile">AudioFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.AudioFile.html">dcase_framework.files.AudioFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.AudioFile.load.html">dcase_framework.files.AudioFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.AudioFile.save.html">dcase_framework.files.AudioFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.AudioFile.exists.html">dcase_framework.files.AudioFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.AudioFile.empty.html">dcase_framework.files.AudioFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#parameterfile">ParameterFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ParameterFile.html">dcase_framework.files.ParameterFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ParameterFile.load.html">dcase_framework.files.ParameterFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ParameterFile.save.html">dcase_framework.files.ParameterFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ParameterFile.exists.html">dcase_framework.files.ParameterFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ParameterFile.empty.html">dcase_framework.files.ParameterFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#featurefile">FeatureFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FeatureFile.html">dcase_framework.files.FeatureFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FeatureFile.load.html">dcase_framework.files.FeatureFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FeatureFile.save.html">dcase_framework.files.FeatureFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FeatureFile.exists.html">dcase_framework.files.FeatureFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FeatureFile.empty.html">dcase_framework.files.FeatureFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#datafile">DataFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DataFile.html">dcase_framework.files.DataFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DataFile.load.html">dcase_framework.files.DataFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DataFile.save.html">dcase_framework.files.DataFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DataFile.exists.html">dcase_framework.files.DataFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DataFile.empty.html">dcase_framework.files.DataFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#repositoryfile">RepositoryFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.RepositoryFile.html">dcase_framework.files.RepositoryFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.RepositoryFile.load.html">dcase_framework.files.RepositoryFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.RepositoryFile.exists.html">dcase_framework.files.RepositoryFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.RepositoryFile.empty.html">dcase_framework.files.RepositoryFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#textfile">TextFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.TextFile.html">dcase_framework.files.TextFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.TextFile.load.html">dcase_framework.files.TextFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.TextFile.save.html">dcase_framework.files.TextFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.TextFile.exists.html">dcase_framework.files.TextFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.TextFile.empty.html">dcase_framework.files.TextFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#dictfile">DictFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DictFile.html">dcase_framework.files.DictFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DictFile.load.html">dcase_framework.files.DictFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DictFile.save.html">dcase_framework.files.DictFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DictFile.exists.html">dcase_framework.files.DictFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.DictFile.empty.html">dcase_framework.files.DictFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#listfile">ListFile</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ListFile.html">dcase_framework.files.ListFile</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ListFile.load.html">dcase_framework.files.ListFile.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ListFile.save.html">dcase_framework.files.ListFile.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ListFile.exists.html">dcase_framework.files.ListFile.exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.ListFile.empty.html">dcase_framework.files.ListFile.empty</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../files.html#mixins">Mixins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.files.FileMixin.html">dcase_framework.files.FileMixin</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../datasets.html">Datasets</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../datasets.html#dataset-base-class">Dataset - Base class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.html">dcase_framework.datasets.Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.initialize.html">dcase_framework.datasets.Dataset.initialize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.show_info.html">dcase_framework.datasets.Dataset.show_info</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.audio_files.html">dcase_framework.datasets.Dataset.audio_files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.audio_file_count.html">dcase_framework.datasets.Dataset.audio_file_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.meta.html">dcase_framework.datasets.Dataset.meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.meta_count.html">dcase_framework.datasets.Dataset.meta_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.error_meta.html">dcase_framework.datasets.Dataset.error_meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.error_meta_count.html">dcase_framework.datasets.Dataset.error_meta_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.fold_count.html">dcase_framework.datasets.Dataset.fold_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.scene_labels.html">dcase_framework.datasets.Dataset.scene_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.scene_label_count.html">dcase_framework.datasets.Dataset.scene_label_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.event_labels.html">dcase_framework.datasets.Dataset.event_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.event_label_count.html">dcase_framework.datasets.Dataset.event_label_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.audio_tags.html">dcase_framework.datasets.Dataset.audio_tags</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.audio_tag_count.html">dcase_framework.datasets.Dataset.audio_tag_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.download_packages.html">dcase_framework.datasets.Dataset.download_packages</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.extract.html">dcase_framework.datasets.Dataset.extract</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.train.html">dcase_framework.datasets.Dataset.train</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.test.html">dcase_framework.datasets.Dataset.test</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.eval.html">dcase_framework.datasets.Dataset.eval</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.train_files.html">dcase_framework.datasets.Dataset.train_files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.test_files.html">dcase_framework.datasets.Dataset.test_files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.eval_files.html">dcase_framework.datasets.Dataset.eval_files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.validation_files.html">dcase_framework.datasets.Dataset.validation_files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.folds.html">dcase_framework.datasets.Dataset.folds</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.file_meta.html">dcase_framework.datasets.Dataset.file_meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.file_error_meta.html">dcase_framework.datasets.Dataset.file_error_meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.file_error_meta.html">dcase_framework.datasets.Dataset.file_error_meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.relative_to_absolute_path.html">dcase_framework.datasets.Dataset.relative_to_absolute_path</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.Dataset.absolute_to_relative.html">dcase_framework.datasets.Dataset.absolute_to_relative</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../datasets.html#acousticscenedataset">AcousticSceneDataset</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.AcousticSceneDataset.html">dcase_framework.datasets.AcousticSceneDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTAcousticScenes_2017_DevelopmentSet.html">dcase_framework.datasets.TUTAcousticScenes_2017_DevelopmentSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTAcousticScenes_2016_DevelopmentSet.html">dcase_framework.datasets.TUTAcousticScenes_2016_DevelopmentSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTAcousticScenes_2016_EvaluationSet.html">dcase_framework.datasets.TUTAcousticScenes_2016_EvaluationSet</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../datasets.html#soundeventdataset">SoundEventDataset</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.SoundEventDataset.html">dcase_framework.datasets.SoundEventDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.SoundEventDataset.event_label_count.html">dcase_framework.datasets.SoundEventDataset.event_label_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.SoundEventDataset.event_labels.html">dcase_framework.datasets.SoundEventDataset.event_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.SoundEventDataset.train.html">dcase_framework.datasets.SoundEventDataset.train</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.SoundEventDataset.test.html">dcase_framework.datasets.SoundEventDataset.test</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTRareSoundEvents_2017_DevelopmentSet.html">dcase_framework.datasets.TUTRareSoundEvents_2017_DevelopmentSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTSoundEvents_2017_DevelopmentSet.html">dcase_framework.datasets.TUTSoundEvents_2017_DevelopmentSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTSoundEvents_2016_DevelopmentSet.html">dcase_framework.datasets.TUTSoundEvents_2016_DevelopmentSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.TUTSoundEvents_2016_EvaluationSet.html">dcase_framework.datasets.TUTSoundEvents_2016_EvaluationSet</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../datasets.html#audiotaggingdataset">AudioTaggingDataset</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.datasets.AudioTaggingDataset.html">dcase_framework.datasets.AudioTaggingDataset</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../metadata.html">Meta data</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../metadata.html#metadataitem">MetaDataItem</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.html">dcase_framework.metadata.MetaDataItem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.id.html">dcase_framework.metadata.MetaDataItem.id</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.file.html">dcase_framework.metadata.MetaDataItem.file</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.scene_label.html">dcase_framework.metadata.MetaDataItem.scene_label</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.event_label.html">dcase_framework.metadata.MetaDataItem.event_label</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.event_onset.html">dcase_framework.metadata.MetaDataItem.event_onset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.event_offset.html">dcase_framework.metadata.MetaDataItem.event_offset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.identifier.html">dcase_framework.metadata.MetaDataItem.identifier</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataItem.source_label.html">dcase_framework.metadata.MetaDataItem.source_label</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata.html#metadatacontainer">MetaDataContainer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.html">dcase_framework.metadata.MetaDataContainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.log.html">dcase_framework.metadata.MetaDataContainer.log</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.show.html">dcase_framework.metadata.MetaDataContainer.show</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.get_string.html">dcase_framework.metadata.MetaDataContainer.get_string</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.update.html">dcase_framework.metadata.MetaDataContainer.update</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.filter.html">dcase_framework.metadata.MetaDataContainer.filter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.filter_time_segment.html">dcase_framework.metadata.MetaDataContainer.filter_time_segment</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.process_events.html">dcase_framework.metadata.MetaDataContainer.process_events</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.remove_field.html">dcase_framework.metadata.MetaDataContainer.remove_field</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.slice_field.html">dcase_framework.metadata.MetaDataContainer.slice_field</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.filter_time_segment.html">dcase_framework.metadata.MetaDataContainer.filter_time_segment</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.add_time_offset.html">dcase_framework.metadata.MetaDataContainer.add_time_offset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.file_list.html">dcase_framework.metadata.MetaDataContainer.file_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.event_count.html">dcase_framework.metadata.MetaDataContainer.event_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.scene_label_count.html">dcase_framework.metadata.MetaDataContainer.scene_label_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.event_label_count.html">dcase_framework.metadata.MetaDataContainer.event_label_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.unique_scene_labels.html">dcase_framework.metadata.MetaDataContainer.unique_scene_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.unique_event_labels.html">dcase_framework.metadata.MetaDataContainer.unique_event_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.max_offset.html">dcase_framework.metadata.MetaDataContainer.max_offset</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.load.html">dcase_framework.metadata.MetaDataContainer.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.save.html">dcase_framework.metadata.MetaDataContainer.save</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.event_stat_counts.html">dcase_framework.metadata.MetaDataContainer.event_stat_counts</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.MetaDataContainer.event_roll.html">dcase_framework.metadata.MetaDataContainer.event_roll</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata.html#eventroll">EventRoll</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.EventRoll.html">dcase_framework.metadata.EventRoll</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.EventRoll.roll.html">dcase_framework.metadata.EventRoll.roll</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.EventRoll.pad.html">dcase_framework.metadata.EventRoll.pad</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.EventRoll.plot.html">dcase_framework.metadata.EventRoll.plot</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata.html#probabilityitem">ProbabilityItem</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.html">dcase_framework.metadata.ProbabilityItem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.id.html">dcase_framework.metadata.ProbabilityItem.id</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.file.html">dcase_framework.metadata.ProbabilityItem.file</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.label.html">dcase_framework.metadata.ProbabilityItem.label</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.timestamp.html">dcase_framework.metadata.ProbabilityItem.timestamp</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.probability.html">dcase_framework.metadata.ProbabilityItem.probability</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityItem.get_list.html">dcase_framework.metadata.ProbabilityItem.get_list</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata.html#probabilitycontainer">ProbabilityContainer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.html">dcase_framework.metadata.ProbabilityContainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.log.html">dcase_framework.metadata.ProbabilityContainer.log</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.show.html">dcase_framework.metadata.ProbabilityContainer.show</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.update.html">dcase_framework.metadata.ProbabilityContainer.update</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.file_list.html">dcase_framework.metadata.ProbabilityContainer.file_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.unique_labels.html">dcase_framework.metadata.ProbabilityContainer.unique_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.filter.html">dcase_framework.metadata.ProbabilityContainer.filter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.get_string.html">dcase_framework.metadata.ProbabilityContainer.get_string</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.load.html">dcase_framework.metadata.ProbabilityContainer.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.metadata.ProbabilityContainer.save.html">dcase_framework.metadata.ProbabilityContainer.save</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../features.html">Features</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featurecontainer">FeatureContainer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.html">dcase_framework.features.FeatureContainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.show.html">dcase_framework.features.FeatureContainer.show</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.log.html">dcase_framework.features.FeatureContainer.log</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.get_path.html">dcase_framework.features.FeatureContainer.get_path</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.shape.html">dcase_framework.features.FeatureContainer.shape</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.channels.html">dcase_framework.features.FeatureContainer.channels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.frames.html">dcase_framework.features.FeatureContainer.frames</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.vector_length.html">dcase_framework.features.FeatureContainer.vector_length</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.feat.html">dcase_framework.features.FeatureContainer.feat</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.stat.html">dcase_framework.features.FeatureContainer.stat</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.meta.html">dcase_framework.features.FeatureContainer.meta</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureContainer.load.html">dcase_framework.features.FeatureContainer.load</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featurerepository">FeatureRepository</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureRepository.html">dcase_framework.features.FeatureRepository</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureRepository.show.html">dcase_framework.features.FeatureRepository.show</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureRepository.log.html">dcase_framework.features.FeatureRepository.log</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureRepository.get_path.html">dcase_framework.features.FeatureRepository.get_path</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureRepository.load.html">dcase_framework.features.FeatureRepository.load</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featureextractor">FeatureExtractor</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureExtractor.html">dcase_framework.features.FeatureExtractor</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureExtractor.extract.html">dcase_framework.features.FeatureExtractor.extract</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureExtractor.get_default_parameters.html">dcase_framework.features.FeatureExtractor.get_default_parameters</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featurenormalizer">FeatureNormalizer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureNormalizer.html">dcase_framework.features.FeatureNormalizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureNormalizer.accumulate.html">dcase_framework.features.FeatureNormalizer.accumulate</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureNormalizer.finalize.html">dcase_framework.features.FeatureNormalizer.finalize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureNormalizer.normalize.html">dcase_framework.features.FeatureNormalizer.normalize</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureNormalizer.process.html">dcase_framework.features.FeatureNormalizer.process</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featurestacker">FeatureStacker</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureStacker.html">dcase_framework.features.FeatureStacker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureStacker.normalizer.html">dcase_framework.features.FeatureStacker.normalizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureStacker.feature_vector.html">dcase_framework.features.FeatureStacker.feature_vector</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureStacker.process.html">dcase_framework.features.FeatureStacker.process</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featureaggregator">FeatureAggregator</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureAggregator.html">dcase_framework.features.FeatureAggregator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureAggregator.process.html">dcase_framework.features.FeatureAggregator.process</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../features.html#featuremasker">FeatureMasker</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureMasker.html">dcase_framework.features.FeatureMasker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.features.FeatureMasker.process.html">dcase_framework.features.FeatureMasker.process</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../learners.html">Learners</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../learners.html#sceneclassifier">SceneClassifier</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#sceneclassifiergmm">SceneClassifierGMM</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierGMM.html">dcase_framework.learners.SceneClassifierGMM</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierGMM.learn.html">dcase_framework.learners.SceneClassifierGMM.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierGMM.predict.html">dcase_framework.learners.SceneClassifierGMM.predict</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#sceneclassifiermlp">SceneClassifierMLP</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierMLP.html">dcase_framework.learners.SceneClassifierMLP</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierMLP.learn.html">dcase_framework.learners.SceneClassifierMLP.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierMLP.predict.html">dcase_framework.learners.SceneClassifierMLP.predict</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#sceneclassifierkerassequential">SceneClassifierKerasSequential</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.html">dcase_framework.learners.SceneClassifierKerasSequential</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.learn.html">dcase_framework.learners.SceneClassifierKerasSequential.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.predict.html">dcase_framework.learners.SceneClassifierKerasSequential.predict</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../learners.html#eventdetector">EventDetector</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetector.html">dcase_framework.learners.EventDetector</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#eventdetectorgmm">EventDetectorGMM</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorGMM.html">dcase_framework.learners.EventDetectorGMM</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorGMM.learn.html">dcase_framework.learners.EventDetectorGMM.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorGMM.predict.html">dcase_framework.learners.EventDetectorGMM.predict</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#eventdetectormlp">EventDetectorMLP</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorMLP.html">dcase_framework.learners.EventDetectorMLP</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorMLP.learn.html">dcase_framework.learners.EventDetectorMLP.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorMLP.predict.html">dcase_framework.learners.EventDetectorMLP.predict</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../learners.html#eventdetectorkerassequential">EventDetectorKerasSequential</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.html">dcase_framework.learners.EventDetectorKerasSequential</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.learn.html">dcase_framework.learners.EventDetectorKerasSequential.learn</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.predict.html">dcase_framework.learners.EventDetectorKerasSequential.predict</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../learners.html#learnercontainer-base-class">LearnerContainer - Base class</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.html">dcase_framework.learners.LearnerContainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.class_labels.html">dcase_framework.learners.LearnerContainer.class_labels</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.method.html">dcase_framework.learners.LearnerContainer.method</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.params.html">dcase_framework.learners.LearnerContainer.params</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.feature_masker.html">dcase_framework.learners.LearnerContainer.feature_masker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.feature_normalizer.html">dcase_framework.learners.LearnerContainer.feature_normalizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.feature_stacker.html">dcase_framework.learners.LearnerContainer.feature_stacker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.feature_aggregator.html">dcase_framework.learners.LearnerContainer.feature_aggregator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.model.html">dcase_framework.learners.LearnerContainer.model</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.set_seed.html">dcase_framework.learners.LearnerContainer.set_seed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.learners.LearnerContainer.learner_params.html">dcase_framework.learners.LearnerContainer.learner_params</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../recognizers.html">Recognizers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../recognizers.html#scenerecognizer">SceneRecognizer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.SceneRecognizer.html">dcase_framework.recognizers.SceneRecognizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.SceneRecognizer.process.html">dcase_framework.recognizers.SceneRecognizer.process</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../recognizers.html#eventrecognizer">EventRecognizer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.EventRecognizer.html">dcase_framework.recognizers.EventRecognizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.EventRecognizer.process.html">dcase_framework.recognizers.EventRecognizer.process</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.EventRecognizer.process_ratio.html">dcase_framework.recognizers.EventRecognizer.process_ratio</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../recognizers.html#baserecognizer">BaseRecognizer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.BaseRecognizer.html">dcase_framework.recognizers.BaseRecognizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.BaseRecognizer.collapse_probabilities.html">dcase_framework.recognizers.BaseRecognizer.collapse_probabilities</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.BaseRecognizer.collapse_probabilities_windowed.html">dcase_framework.recognizers.BaseRecognizer.collapse_probabilities_windowed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.BaseRecognizer.find_contiguous_regions.html">dcase_framework.recognizers.BaseRecognizer.find_contiguous_regions</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.recognizers.BaseRecognizer.process_activity.html">dcase_framework.recognizers.BaseRecognizer.process_activity</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../data.html">Data utils</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../data.html#datasequencer">DataSequencer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataSequencer.html">dcase_framework.data.DataSequencer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataSequencer.process.html">dcase_framework.data.DataSequencer.process</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataSequencer.increase_shifting.html">dcase_framework.data.DataSequencer.increase_shifting</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../data.html#dataprocessor">DataProcessor</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.html">dcase_framework.data.DataProcessor</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.load.html">dcase_framework.data.DataProcessor.load</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.process.html">dcase_framework.data.DataProcessor.process</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.process_features.html">dcase_framework.data.DataProcessor.process_features</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.process_activity_data.html">dcase_framework.data.DataProcessor.process_activity_data</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.process_data.html">dcase_framework.data.DataProcessor.process_data</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataProcessor.call_method.html">dcase_framework.data.DataProcessor.call_method</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../data.html#databuffer">DataBuffer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.html">dcase_framework.data.DataBuffer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.count.html">dcase_framework.data.DataBuffer.count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.full.html">dcase_framework.data.DataBuffer.full</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.key_exists.html">dcase_framework.data.DataBuffer.key_exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.set.html">dcase_framework.data.DataBuffer.set</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.get.html">dcase_framework.data.DataBuffer.get</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.DataBuffer.clear.html">dcase_framework.data.DataBuffer.clear</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../data.html#processingchain">ProcessingChain</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.ProcessingChain.html">dcase_framework.data.ProcessingChain</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.ProcessingChain.process.html">dcase_framework.data.ProcessingChain.process</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.data.ProcessingChain.call_method.html">dcase_framework.data.ProcessingChain.call_method</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../keras_utils.html">Keras utils</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#kerasmixin">KerasMixin</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.create_model.html">dcase_framework.keras_utils.KerasMixin.create_model</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.create_callback_list.html">dcase_framework.keras_utils.KerasMixin.create_callback_list</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.create_external_metric_evaluators.html">dcase_framework.keras_utils.KerasMixin.create_external_metric_evaluators</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.prepare_data.html">dcase_framework.keras_utils.KerasMixin.prepare_data</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.prepare_activity.html">dcase_framework.keras_utils.KerasMixin.prepare_activity</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.keras_model_exists.html">dcase_framework.keras_utils.KerasMixin.keras_model_exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.log_model_summary.html">dcase_framework.keras_utils.KerasMixin.log_model_summary</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.plot_model.html">dcase_framework.keras_utils.KerasMixin.plot_model</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.KerasMixin.get_processing_interval.html">dcase_framework.keras_utils.KerasMixin.get_processing_interval</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#basecallback">BaseCallback</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseCallback.html">dcase_framework.keras_utils.BaseCallback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#progressloggercallback">ProgressLoggerCallback</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.ProgressLoggerCallback.html">dcase_framework.keras_utils.ProgressLoggerCallback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#progressplottercallback">ProgressPlotterCallback</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.ProgressPlotterCallback.html">dcase_framework.keras_utils.ProgressPlotterCallback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#stoppercallback">StopperCallback</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.StopperCallback.html">dcase_framework.keras_utils.StopperCallback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#stashercallback">StasherCallback</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.StasherCallback.html">dcase_framework.keras_utils.StasherCallback</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#basedatagenerator">BaseDataGenerator</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseDataGenerator.html">dcase_framework.keras_utils.BaseDataGenerator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseDataGenerator.input_size.html">dcase_framework.keras_utils.BaseDataGenerator.input_size</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseDataGenerator.data_size.html">dcase_framework.keras_utils.BaseDataGenerator.data_size</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseDataGenerator.steps_count.html">dcase_framework.keras_utils.BaseDataGenerator.steps_count</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.BaseDataGenerator.info.html">dcase_framework.keras_utils.BaseDataGenerator.info</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../keras_utils.html#featuregenerator">FeatureGenerator</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.FeatureGenerator.html">dcase_framework.keras_utils.FeatureGenerator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.keras_utils.FeatureGenerator.generator.html">dcase_framework.keras_utils.FeatureGenerator.generator</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../ui.html">User interfacing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../ui.html#fancylogger">FancyLogger</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.html">dcase_framework.ui.FancyLogger</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.title.html">dcase_framework.ui.FancyLogger.title</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.section_header.html">dcase_framework.ui.FancyLogger.section_header</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.foot.html">dcase_framework.ui.FancyLogger.foot</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.line.html">dcase_framework.ui.FancyLogger.line</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.data.html">dcase_framework.ui.FancyLogger.data</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.info.html">dcase_framework.ui.FancyLogger.info</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.debug.html">dcase_framework.ui.FancyLogger.debug</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.ui.FancyLogger.error.html">dcase_framework.ui.FancyLogger.error</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../utils.html">Utils</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../utils.html#utility-functions">Utility functions</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.setup_logging.html">dcase_framework.utils.setup_logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.get_parameter_hash.html">dcase_framework.utils.get_parameter_hash</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.get_class_inheritors.html">dcase_framework.utils.get_class_inheritors</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.get_byte_string.html">dcase_framework.utils.get_byte_string</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.argument_file_exists.html">dcase_framework.utils.argument_file_exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.filelist_exists.html">dcase_framework.utils.filelist_exists</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.posix_path.html">dcase_framework.utils.posix_path</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../utils.html#timer">Timer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.Timer.html">dcase_framework.utils.Timer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.Timer.start.html">dcase_framework.utils.Timer.start</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.Timer.stop.html">dcase_framework.utils.Timer.stop</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.Timer.elapsed.html">dcase_framework.utils.Timer.elapsed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.Timer.get_string.html">dcase_framework.utils.Timer.get_string</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../utils.html#suppressstdoutandstderr">SuppressStdoutAndStderr</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.SuppressStdoutAndStderr.html">dcase_framework.utils.SuppressStdoutAndStderr</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../utils.html#simplemathstringevaluator">SimpleMathStringEvaluator</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.SimpleMathStringEvaluator.html">dcase_framework.utils.SimpleMathStringEvaluator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../generated/dcase_framework.utils.SimpleMathStringEvaluator.eval.html">dcase_framework.utils.SimpleMathStringEvaluator.eval</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">DCASE2017 Baseline</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>dcase_framework.learners</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for dcase_framework.learners</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Learners</span>
<span class="sd">========</span>
<span class="sd">Classes for machine learning</span>

<span class="sd">SceneClassifier</span>
<span class="sd">^^^^^^^^^^^^^^^</span>

<span class="sd">SceneClassifierGMM</span>
<span class="sd">..................</span>

<span class="sd">Scene classifier with GMM. This learner is using ``sklearn.mixture.GaussianMixture`` implementation. See</span>
<span class="sd">`documentation &lt;http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html/&gt;`_.</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    SceneClassifierGMM</span>
<span class="sd">    SceneClassifierGMM.learn</span>
<span class="sd">    SceneClassifierGMM.predict</span>

<span class="sd">SceneClassifierMLP</span>
<span class="sd">..................</span>

<span class="sd">Scene classifier with MLP. This learner is a simple MLP based learner using Keras neural network implementation</span>
<span class="sd">and sequential API. See `documentation &lt;https://keras.io/&gt;`_.</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    SceneClassifierMLP</span>
<span class="sd">    SceneClassifierMLP.learn</span>
<span class="sd">    SceneClassifierMLP.predict</span>

<span class="sd">SceneClassifierKerasSequential</span>
<span class="sd">..............................</span>

<span class="sd">Scene classifier with Keras sequential API (see `documentation &lt;https://keras.io/&gt;`_). This learner can be used for</span>
<span class="sd">more advanced network structures than SceneClassifierMLP.</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    SceneClassifierKerasSequential</span>
<span class="sd">    SceneClassifierKerasSequential.learn</span>
<span class="sd">    SceneClassifierKerasSequential.predict</span>

<span class="sd">EventDetector</span>
<span class="sd">^^^^^^^^^^^^^^^</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    EventDetector</span>

<span class="sd">EventDetectorGMM</span>
<span class="sd">................</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    EventDetectorGMM</span>
<span class="sd">    EventDetectorGMM.learn</span>
<span class="sd">    EventDetectorGMM.predict</span>

<span class="sd">EventDetectorMLP</span>
<span class="sd">................</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    EventDetectorMLP</span>
<span class="sd">    EventDetectorMLP.learn</span>
<span class="sd">    EventDetectorMLP.predict</span>

<span class="sd">EventDetectorKerasSequential</span>
<span class="sd">............................</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    EventDetectorKerasSequential</span>
<span class="sd">    EventDetectorKerasSequential.learn</span>
<span class="sd">    EventDetectorKerasSequential.predict</span>

<span class="sd">LearnerContainer - Base class</span>
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>

<span class="sd">.. autosummary::</span>
<span class="sd">    :toctree: generated/</span>

<span class="sd">    LearnerContainer</span>
<span class="sd">    LearnerContainer.class_labels</span>
<span class="sd">    LearnerContainer.method</span>
<span class="sd">    LearnerContainer.params</span>
<span class="sd">    LearnerContainer.feature_masker</span>
<span class="sd">    LearnerContainer.feature_normalizer</span>
<span class="sd">    LearnerContainer.feature_stacker</span>
<span class="sd">    LearnerContainer.feature_aggregator</span>
<span class="sd">    LearnerContainer.model</span>
<span class="sd">    LearnerContainer.set_seed</span>
<span class="sd">    LearnerContainer.learner_params</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span><span class="p">,</span> <span class="n">absolute_import</span>
<span class="kn">from</span> <span class="nn">six</span> <span class="k">import</span> <span class="n">iteritems</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">numpy</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">copy</span>

<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">sklearn.metrics</span> <span class="k">import</span> <span class="n">mean_absolute_error</span>
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="k">import</span> <span class="n">tqdm</span>

<span class="kn">from</span> <span class="nn">.files</span> <span class="k">import</span> <span class="n">DataFile</span>
<span class="kn">from</span> <span class="nn">.containers</span> <span class="k">import</span> <span class="n">ContainerMixin</span><span class="p">,</span> <span class="n">DottedDict</span>
<span class="kn">from</span> <span class="nn">.features</span> <span class="k">import</span> <span class="n">FeatureContainer</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="k">import</span> <span class="n">SuppressStdoutAndStderr</span>
<span class="kn">from</span> <span class="nn">.metadata</span> <span class="k">import</span> <span class="n">MetaDataItem</span><span class="p">,</span> <span class="n">EventRoll</span>
<span class="kn">from</span> <span class="nn">.keras_utils</span> <span class="k">import</span> <span class="n">KerasMixin</span><span class="p">,</span> <span class="n">BaseDataGenerator</span><span class="p">,</span> <span class="n">StasherCallback</span>
<span class="kn">from</span> <span class="nn">.data</span> <span class="k">import</span> <span class="n">DataSequencer</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="k">import</span> <span class="n">get_class_inheritors</span>
<span class="kn">from</span> <span class="nn">.recognizers</span> <span class="k">import</span> <span class="n">SceneRecognizer</span><span class="p">,</span> <span class="n">EventRecognizer</span>


<span class="k">def</span> <span class="nf">scene_classifier_factory</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;gmm&#39;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">SceneClassifierGMM</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;mlp&#39;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">SceneClassifierMLP</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Invalid SegmentClassifier method [</span><span class="si">{method}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">name</span><span class="o">=</span><span class="s1">&#39;segment_classifier_factory&#39;</span><span class="p">,</span>
            <span class="n">method</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
        <span class="p">)</span>


<span class="k">def</span> <span class="nf">event_detector_factory</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;gmm&#39;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">EventDetectorGMM</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">elif</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;mlp&#39;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">EventDetectorMLP</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">elif</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;keras_seq&#39;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">EventDetectorKerasSequential</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Invalid EventDetector method [</span><span class="si">{method}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">name</span><span class="o">=</span><span class="s1">&#39;event_detector_factory&#39;</span><span class="p">,</span>
            <span class="n">method</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
        <span class="p">)</span>


<div class="viewcode-block" id="LearnerContainer"><a class="viewcode-back" href="../../generated/dcase_framework.learners.LearnerContainer.html#dcase_framework.learners.LearnerContainer">[docs]</a><span class="k">class</span> <span class="nc">LearnerContainer</span><span class="p">(</span><span class="n">DataFile</span><span class="p">,</span> <span class="n">ContainerMixin</span><span class="p">):</span>
    <span class="n">valid_formats</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;cpickle&#39;</span><span class="p">]</span>

<div class="viewcode-block" id="LearnerContainer.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.LearnerContainer.html#dcase_framework.learners.LearnerContainer.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Constructor</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        method : str</span>
<span class="sd">            Method label</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        class_labels : list of strings</span>
<span class="sd">            List of class labels</span>
<span class="sd">            Default value &quot;[]&quot;</span>
<span class="sd">        params : dict or DottedDict</span>
<span class="sd">            Parameters</span>
<span class="sd">        feature_masker : FeatureMasker or class inherited from FeatureMasker</span>
<span class="sd">            Feature masker instance</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        feature_normalizer : FeatureNormalizer or class inherited from FeatureNormalizer</span>
<span class="sd">            Feature normalizer instance</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        feature_stacker : FeatureStacker or class inherited from FeatureStacker</span>
<span class="sd">            Feature stacker instance</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        feature_aggregator : FeatureAggregator or class inherited from FeatureAggregator</span>
<span class="sd">            Feature aggregator instance</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        logger : logging</span>
<span class="sd">            Instance of logging</span>
<span class="sd">            Default value &quot;None&quot;</span>
<span class="sd">        disable_progress_bar : bool</span>
<span class="sd">            Disable progress bar in console</span>
<span class="sd">            Default value &quot;False&quot;</span>
<span class="sd">        log_progress : bool</span>
<span class="sd">            Show progress in log.</span>
<span class="sd">            Default value &quot;False&quot;</span>
<span class="sd">        show_extra_debug : bool</span>
<span class="sd">            Show extra debug information</span>
<span class="sd">            Default value &quot;True&quot;</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">LearnerContainer</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">({</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="s1">&#39;class_labels&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;class_labels&#39;</span><span class="p">,</span> <span class="p">[]),</span>
            <span class="s1">&#39;params&#39;</span><span class="p">:</span> <span class="n">DottedDict</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{})),</span>
            <span class="s1">&#39;feature_masker&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_masker&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="s1">&#39;feature_normalizer&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_normalizer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="s1">&#39;feature_stacker&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_stacker&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="s1">&#39;feature_aggregator&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_aggregator&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="s1">&#39;model&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">,</span> <span class="p">{}),</span>
            <span class="s1">&#39;learning_history&#39;</span><span class="p">:</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;learning_history&#39;</span><span class="p">,</span> <span class="p">{}),</span>
        <span class="p">},</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="c1"># Set randomization seed</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;seed&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;seed&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;parameters.seed&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;parameters.seed&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;seed&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;seed&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">epoch</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcfromtimestamp</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">unix_now</span> <span class="o">=</span> <span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">epoch</span><span class="p">)</span><span class="o">.</span><span class="n">total_seconds</span><span class="p">()</span> <span class="o">*</span> <span class="mf">1000.0</span>
            <span class="n">bigint</span><span class="p">,</span> <span class="n">mod</span> <span class="o">=</span> <span class="nb">divmod</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">unix_now</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">,</span> <span class="mi">2</span><span class="o">**</span><span class="mi">32</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="n">mod</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;logger&#39;</span><span class="p">,</span>  <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">disable_progress_bar</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;disable_progress_bar&#39;</span><span class="p">,</span>  <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_progress</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;log_progress&#39;</span><span class="p">,</span>  <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;show_extra_debug&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">class_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Class labels</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        list of strings</span>
<span class="sd">            List of class labels in the model</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;class_labels&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>

    <span class="nd">@class_labels</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">class_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;class_labels&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">method</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learner method label</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        str</span>
<span class="sd">            Learner method label</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@method</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">method</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;method&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Parameters</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        DottedDict</span>
<span class="sd">            Parameters</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@params</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">feature_masker</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature masker instance</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        FeatureMasker</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_masker&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@feature_masker</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">feature_masker</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;feature_masker&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">feature_normalizer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature normalizer instance</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        FeatureNormalizer</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_normalizer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@feature_normalizer</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">feature_normalizer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;feature_normalizer&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">feature_stacker</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature stacker instance</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        FeatureStacker</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_stacker&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@feature_stacker</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">feature_stacker</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;feature_stacker&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">feature_aggregator</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature aggregator instance</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        FeatureAggregator</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;feature_aggregator&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@feature_aggregator</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">feature_aggregator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;feature_aggregator&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Acoustic model</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        model</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@model</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="LearnerContainer.set_seed"><a class="viewcode-back" href="../../generated/dcase_framework.learners.LearnerContainer.set_seed.html#dcase_framework.learners.LearnerContainer.set_seed">[docs]</a>    <span class="k">def</span> <span class="nf">set_seed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set randomization seeds</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        nothing</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">seed</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">seed</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">seed</span>

        <span class="n">numpy</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span>
        <span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">learner_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get learner parameters from parameter container</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        DottedDict</span>
<span class="sd">            Learner parameters</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="s1">&#39;parameters&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]:</span>
            <span class="n">parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">][</span><span class="s1">&#39;parameters&#39;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">DottedDict</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">parameters</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)})</span>

    <span class="k">def</span> <span class="nf">_get_input_size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="n">input_shape</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">input_shape</span><span class="p">:</span>
                <span class="n">input_shape</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">input_shape</span> <span class="o">!=</span> <span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Input size not coherent.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">input_shape</span></div>


<div class="viewcode-block" id="SceneClassifier"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifier.html#dcase_framework.learners.SceneClassifier">[docs]</a><span class="k">class</span> <span class="nc">SceneClassifier</span><span class="p">(</span><span class="n">LearnerContainer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Scene classifier (Frame classifier / Multi-class - Single-label)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Predict frame probabilities for given feature matrix</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        feature_data : numpy.ndarray</span>
<span class="sd">            Feature data</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        str</span>
<span class="sd">            class label</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="n">FeatureContainer</span><span class="p">):</span>
            <span class="c1"># If we have featureContainer as input, get feature_data</span>
            <span class="n">feature_data</span> <span class="o">=</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Get frame probabilities</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_frame_probabilities</span><span class="p">(</span><span class="n">feature_data</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_generate_validation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">validation_type</span><span class="o">=</span><span class="s1">&#39;generated_scene_balanced&#39;</span><span class="p">,</span>
                             <span class="n">valid_percentage</span><span class="o">=</span><span class="mf">0.20</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">(</span><span class="n">seed</span><span class="o">=</span><span class="n">seed</span><span class="p">)</span>
        <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="n">validation_type</span> <span class="o">==</span> <span class="s1">&#39;generated_scene_balanced&#39;</span><span class="p">:</span>
            <span class="c1"># Get training data per scene label</span>
            <span class="n">annotation_data</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
                <span class="n">scene_label</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="s1">&#39;scene_label&#39;</span><span class="p">]</span>
                <span class="n">location_id</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="s1">&#39;identifier&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">scene_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">annotation_data</span><span class="p">:</span>
                    <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">if</span> <span class="n">location_id</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]:</span>
                    <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">audio_filename</span><span class="p">)</span>

            <span class="n">training_files</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">validation_amounts</span> <span class="o">=</span> <span class="p">{}</span>

            <span class="k">for</span> <span class="n">scene_label</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">annotation_data</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                <span class="n">validation_amount</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">sets_candidates</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1000</span><span class="p">):</span>
                    <span class="n">current_locations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
                    <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">current_locations</span><span class="p">,</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">)</span>
                    <span class="n">valid_percentage_index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">valid_percentage</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">])))</span>
                    <span class="n">current_validation_locations</span> <span class="o">=</span> <span class="n">current_locations</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">valid_percentage_index</span><span class="p">]</span>
                    <span class="n">current_training_locations</span> <span class="o">=</span> <span class="n">current_locations</span><span class="p">[</span><span class="n">valid_percentage_index</span><span class="p">:]</span>

                    <span class="c1"># Collect validation files</span>
                    <span class="n">current_validation_files</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">location_id</span> <span class="ow">in</span> <span class="n">current_validation_locations</span><span class="p">:</span>
                        <span class="n">current_validation_files</span> <span class="o">+=</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span>

                    <span class="c1"># Collect training files</span>
                        <span class="n">current_training_files</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">location_id</span> <span class="ow">in</span> <span class="n">current_training_locations</span><span class="p">:</span>
                        <span class="n">current_training_files</span> <span class="o">+=</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span>

                    <span class="n">validation_amount</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="nb">len</span><span class="p">(</span><span class="n">current_validation_files</span><span class="p">)</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">current_validation_files</span><span class="p">)</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">current_training_files</span><span class="p">))</span>
                    <span class="p">)</span>

                    <span class="n">sets_candidates</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
                        <span class="s1">&#39;validation&#39;</span><span class="p">:</span> <span class="n">current_validation_files</span><span class="p">,</span>
                        <span class="s1">&#39;training&#39;</span><span class="p">:</span> <span class="n">current_training_files</span><span class="p">,</span>
                    <span class="p">})</span>

                <span class="n">best_set_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">validation_amount</span><span class="p">)</span> <span class="o">-</span> <span class="n">valid_percentage</span><span class="p">))</span>
                <span class="n">validation_files</span> <span class="o">+=</span> <span class="n">sets_candidates</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">][</span><span class="s1">&#39;validation&#39;</span><span class="p">]</span>
                <span class="n">training_files</span> <span class="o">+=</span> <span class="n">sets_candidates</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">][</span><span class="s1">&#39;training&#39;</span><span class="p">]</span>
                <span class="n">validation_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">validation_amount</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Validation set statistics&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{0:&lt;20s}</span><span class="s1"> | </span><span class="si">{1:10s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Scene label&#39;</span><span class="p">,</span> <span class="s1">&#39;Validation amount (%)&#39;</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{0:&lt;20s}</span><span class="s1"> + </span><span class="si">{1:10s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="o">*</span><span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="o">*</span><span class="mi">20</span><span class="p">))</span>

                <span class="k">for</span> <span class="n">scene_label</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">validation_amounts</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{0:&lt;20s}</span><span class="s1"> | </span><span class="si">{1:4.2f}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">scene_label</span><span class="p">,</span> <span class="n">validation_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span><span class="o">*</span><span class="mi">100</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation_type [</span><span class="si">{type}</span><span class="s1">].&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="nb">type</span><span class="o">=</span><span class="n">validation_type</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">AssertionError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">validation_files</span>

    <span class="k">def</span> <span class="nf">_frame_probabilities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>
        <span class="c1"># Implement in child class</span>
        <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_get_target_matrix_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">):</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
            <span class="n">frame_count</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="s1">&#39;scene_label&#39;</span><span class="p">])</span>
            <span class="n">roll</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">frame_count</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">)))</span>
            <span class="n">roll</span><span class="p">[:,</span> <span class="n">pos</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span> <span class="o">=</span> <span class="n">roll</span>
        <span class="k">return</span> <span class="n">activity_matrix_dict</span>

    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Implement learn function.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">AssertionError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span></div>


<div class="viewcode-block" id="SceneClassifierGMM"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierGMM.html#dcase_framework.learners.SceneClassifierGMM">[docs]</a><span class="k">class</span> <span class="nc">SceneClassifierGMM</span><span class="p">(</span><span class="n">SceneClassifier</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Scene classifier with GMM</span>

<span class="sd">    This learner is using ``sklearn.mixture.GaussianMixture`` implementation. See</span>
<span class="sd">    `documentation &lt;http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html/&gt;`_.</span>

<span class="sd">    Usage example:</span>

<span class="sd">    .. code-block:: python</span>
<span class="sd">        :linenos:</span>

<span class="sd">        # Audio files</span>
<span class="sd">        files = [&#39;example1.wav&#39;, &#39;example2.wav&#39;, &#39;example3.wav&#39;]</span>

<span class="sd">        # Meta data</span>
<span class="sd">        annotations = {</span>
<span class="sd">            &#39;example1.wav&#39;: MetaDataItem(</span>
<span class="sd">                {</span>
<span class="sd">                    &#39;file&#39;: &#39;example1.wav&#39;,</span>
<span class="sd">                    &#39;scene_label&#39;: &#39;SceneA&#39;</span>
<span class="sd">                }</span>
<span class="sd">            ),</span>
<span class="sd">            &#39;example2.wav&#39;:MetaDataItem(</span>
<span class="sd">                {</span>
<span class="sd">                    &#39;file&#39;: &#39;example2.wav&#39;,</span>
<span class="sd">                    &#39;scene_label&#39;: &#39;SceneB&#39;</span>
<span class="sd">                }</span>
<span class="sd">            ),</span>
<span class="sd">            &#39;example3.wav&#39;: MetaDataItem(</span>
<span class="sd">                {</span>
<span class="sd">                    &#39;file&#39;: &#39;example3.wav&#39;,</span>
<span class="sd">                    &#39;scene_label&#39;: &#39;SceneC&#39;</span>
<span class="sd">                }</span>
<span class="sd">            ),</span>
<span class="sd">        }</span>

<span class="sd">        # Extract features</span>
<span class="sd">        feature_data = {}</span>
<span class="sd">        for file in files:</span>
<span class="sd">            feature_data[file] = FeatureExtractor().extract(</span>
<span class="sd">                audio_file=file,</span>
<span class="sd">                extractor_name=&#39;mfcc&#39;,</span>
<span class="sd">                extractor_params={</span>
<span class="sd">                    &#39;mfcc&#39;: {</span>
<span class="sd">                        &#39;n_mfcc&#39;: 10</span>
<span class="sd">                    }</span>
<span class="sd">                }</span>
<span class="sd">            )[&#39;mfcc&#39;]</span>

<span class="sd">        # Learn acoustic model</span>
<span class="sd">        learner_params = {</span>
<span class="sd">            &#39;n_components&#39;: 1,</span>
<span class="sd">            &#39;covariance_type&#39;: &#39;diag&#39;,</span>
<span class="sd">            &#39;tol&#39;: 0.001,</span>
<span class="sd">            &#39;reg_covar&#39;: 0,</span>
<span class="sd">            &#39;max_iter&#39;: 40,</span>
<span class="sd">            &#39;n_init&#39;: 1,</span>
<span class="sd">            &#39;init_params&#39;: &#39;kmeans&#39;,</span>
<span class="sd">            &#39;random_state&#39;: 0,</span>
<span class="sd">        }</span>

<span class="sd">        gmm_learner = SceneClassifierGMM(</span>
<span class="sd">            filename=&#39;gmm_model.cpickle&#39;,</span>
<span class="sd">            class_labels=[&#39;SceneA&#39;, &#39;SceneB&#39;, &#39;SceneC&#39;],</span>
<span class="sd">            params=learner_params,</span>
<span class="sd">        )</span>

<span class="sd">        gmm_learner.learn(</span>
<span class="sd">            data=feature_data,</span>
<span class="sd">            annotations=annotations</span>
<span class="sd">        )</span>

<span class="sd">        # Recognition</span>
<span class="sd">        recognizer_params = {</span>
<span class="sd">            &#39;frame_accumulation&#39;: {</span>
<span class="sd">                &#39;enable&#39;: True,</span>
<span class="sd">                &#39;type&#39;: &#39;sum&#39;</span>
<span class="sd">            },</span>
<span class="sd">            &#39;decision_making&#39;: {</span>
<span class="sd">                &#39;enable&#39;: True,</span>
<span class="sd">                &#39;type&#39;: &#39;maximum&#39;,</span>
<span class="sd">            }</span>
<span class="sd">        }</span>
<span class="sd">        correctly_predicted = 0</span>
<span class="sd">        for file in feature_data:</span>
<span class="sd">            frame_probabilities = gmm_learner.predict(</span>
<span class="sd">                feature_data=feature_data[file],</span>
<span class="sd">            )</span>

<span class="sd">            # Scene recognizer</span>
<span class="sd">            current_result = SceneRecognizer(</span>
<span class="sd">                params=recognizer_params,</span>
<span class="sd">                class_labels=gmm_learner.class_labels,</span>
<span class="sd">            ).process(</span>
<span class="sd">                frame_probabilities=frame_probabilities</span>
<span class="sd">            )</span>

<span class="sd">            if annotations[file].scene_label == current_result:</span>
<span class="sd">                correctly_predicted += 1</span>
<span class="sd">            print(current_result, annotations[file].scene_label)</span>

<span class="sd">        print(&#39;Accuracy = {:3.2f} %&#39;.format(correctly_predicted/float(len(feature_data))*100))</span>

<span class="sd">    **Learner parameters**</span>

<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | Field name                     | Value type   | Description                                                      |</span>
<span class="sd">    +================================+==============+==================================================================+</span>
<span class="sd">    | n_components                   | int          | The number of mixture components.                                |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | covariance_type                | string       | Covariance type.                                                 |</span>
<span class="sd">    |                                | { full |     |                                                                  |</span>
<span class="sd">    |                                | tied |       |                                                                  |</span>
<span class="sd">    |                                | diag |       |                                                                  |</span>
<span class="sd">    |                                | spherical }  |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | tol                            | float        | Covariance threshold.                                            |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | reg_covar                      | float        | Non-negative regularization added to the diagonal of covariance. |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | max_iter                       | int          | The number of EM iterations.                                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | n_init                         | int          | The number of initializations.                                   |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | init_params                    | string       | The method used to initialize model weights.                     |</span>
<span class="sd">    |                                | { kmeans |   |                                                                  |</span>
<span class="sd">    |                                | random }     |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | random_state                   | int          | Random seed.                                                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>

<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="SceneClassifierGMM.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierGMM.html#dcase_framework.learners.SceneClassifierGMM.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;show_model_information&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;audio_error_handling&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;gmm&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;covariance_type&#39;</span><span class="p">:</span> <span class="s1">&#39;diag&#39;</span><span class="p">,</span>
                <span class="s1">&#39;init_params&#39;</span><span class="p">:</span> <span class="s1">&#39;kmeans&#39;</span><span class="p">,</span>
                <span class="s1">&#39;max_iter&#39;</span><span class="p">:</span> <span class="mi">40</span><span class="p">,</span>
                <span class="s1">&#39;n_components&#39;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                <span class="s1">&#39;n_init&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                <span class="s1">&#39;random_state&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;reg_covar&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;tol&#39;</span><span class="p">:</span> <span class="mf">0.001</span>
            <span class="p">},</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">SceneClassifierGMM</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;gmm&#39;</span></div>

<div class="viewcode-block" id="SceneClassifierGMM.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierGMM.learn.html#dcase_framework.learners.SceneClassifierGMM.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Validation is not implemented for this learner.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="kn">from</span> <span class="nn">sklearn.mixture</span> <span class="k">import</span> <span class="n">GaussianMixture</span>

        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>  <span class="c1"># Collect training files</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>
        <span class="n">X_training</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">vstack</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">training_files</span><span class="p">])</span>
        <span class="n">Y_training</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">vstack</span><span class="p">([</span><span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">training_files</span><span class="p">])</span>

        <span class="n">class_progress</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                              <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span>
                              <span class="n">leave</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                              <span class="n">desc</span><span class="o">=</span><span class="s1">&#39;           </span><span class="si">{0:&gt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Learn &#39;</span><span class="p">),</span>
                              <span class="n">miniters</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                              <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">disable_progress_bar</span>
                              <span class="p">)</span>

        <span class="k">for</span> <span class="n">class_id</span><span class="p">,</span> <span class="n">class_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">class_progress</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_progress</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{title:&lt;15s}</span><span class="s1"> [</span><span class="si">{item_id:d}</span><span class="s1">/</span><span class="si">{total:d}</span><span class="s1">] </span><span class="si">{class_label:&lt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Learn&#39;</span><span class="p">,</span>
                    <span class="n">item_id</span><span class="o">=</span><span class="n">class_id</span><span class="p">,</span>
                    <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span>
                    <span class="n">class_label</span><span class="o">=</span><span class="n">class_label</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="n">current_class_data</span> <span class="o">=</span> <span class="n">X_training</span><span class="p">[</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="n">class_id</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="p">:]</span>

            <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">class_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">GaussianMixture</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">current_class_data</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span></div>

    <span class="k">def</span> <span class="nf">_frame_probabilities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>
        <span class="n">logls</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">]),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">*</span> <span class="o">-</span><span class="n">numpy</span><span class="o">.</span><span class="n">inf</span>

        <span class="k">for</span> <span class="n">label_id</span><span class="p">,</span> <span class="n">label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">):</span>
            <span class="n">logls</span><span class="p">[</span><span class="n">label_id</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">feature_data</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">logls</span></div>


<span class="k">class</span> <span class="nc">SceneClassifierGMMdeprecated</span><span class="p">(</span><span class="n">SceneClassifier</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Scene classifier with GMM&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;show_model_information&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;audio_error_handling&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;gmm_deprecated&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;n_components&#39;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                <span class="s1">&#39;covariance_type&#39;</span><span class="p">:</span> <span class="s1">&#39;diag&#39;</span><span class="p">,</span>
                <span class="s1">&#39;random_state&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;tol&#39;</span><span class="p">:</span> <span class="mf">0.001</span><span class="p">,</span>
                <span class="s1">&#39;min_covar&#39;</span><span class="p">:</span> <span class="mf">0.001</span><span class="p">,</span>
                <span class="s1">&#39;n_iter&#39;</span><span class="p">:</span> <span class="mi">40</span><span class="p">,</span>
                <span class="s1">&#39;n_init&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                <span class="s1">&#39;params&#39;</span><span class="p">:</span> <span class="s1">&#39;wmc&#39;</span><span class="p">,</span>
                <span class="s1">&#39;init_params&#39;</span><span class="p">:</span> <span class="s1">&#39;wmc&#39;</span><span class="p">,</span>
            <span class="p">},</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">SceneClassifierGMMdeprecated</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;gmm_deprecated&#39;</span>

    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Validation is not implemented for this learner.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">)</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="ne">DeprecationWarning</span><span class="p">)</span>
        <span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">mixture</span>

        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>  <span class="c1"># Collect training files</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>
        <span class="n">X_training</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">vstack</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">training_files</span><span class="p">])</span>
        <span class="n">Y_training</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">vstack</span><span class="p">([</span><span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">training_files</span><span class="p">])</span>

        <span class="n">class_progress</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                              <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span>
                              <span class="n">leave</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                              <span class="n">desc</span><span class="o">=</span><span class="s1">&#39;           </span><span class="si">{0:&gt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Learn &#39;</span><span class="p">),</span>
                              <span class="n">miniters</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                              <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">disable_progress_bar</span>
                              <span class="p">)</span>

        <span class="k">for</span> <span class="n">class_id</span><span class="p">,</span> <span class="n">class_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">class_progress</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_progress</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{title:&lt;15s}</span><span class="s1"> [</span><span class="si">{item_id:d}</span><span class="s1">/</span><span class="si">{total:d}</span><span class="s1">] </span><span class="si">{class_label:&lt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Learn&#39;</span><span class="p">,</span>
                    <span class="n">item_id</span><span class="o">=</span><span class="n">class_id</span><span class="p">,</span>
                    <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span>
                    <span class="n">class_label</span><span class="o">=</span><span class="n">class_label</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="n">current_class_data</span> <span class="o">=</span> <span class="n">X_training</span><span class="p">[</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="n">class_id</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="p">:]</span>

            <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">class_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">mixture</span><span class="o">.</span><span class="n">GMM</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">current_class_data</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="nf">_frame_probabilities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">)</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="ne">DeprecationWarning</span><span class="p">)</span>
        <span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">mixture</span>

        <span class="n">logls</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">]),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">*</span> <span class="o">-</span><span class="n">numpy</span><span class="o">.</span><span class="n">inf</span>

        <span class="k">for</span> <span class="n">label_id</span><span class="p">,</span> <span class="n">label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">):</span>
            <span class="n">logls</span><span class="p">[</span><span class="n">label_id</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">label</span><span class="p">]</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">feature_data</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">logls</span>


<div class="viewcode-block" id="SceneClassifierMLP"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierMLP.html#dcase_framework.learners.SceneClassifierMLP">[docs]</a><span class="k">class</span> <span class="nc">SceneClassifierMLP</span><span class="p">(</span><span class="n">SceneClassifier</span><span class="p">,</span> <span class="n">KerasMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Scene classifier with MLP</span>

<span class="sd">    This learner is a simple MLP based learner using Keras neural network implementation and sequential API.</span>
<span class="sd">    See `documentation &lt;https://keras.io/&gt;`_.</span>

<span class="sd">    **Learner parameters**</span>

<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | Field name                     | Value type   | Description                                                      |</span>
<span class="sd">    +================================+==============+==================================================================+</span>
<span class="sd">    | seed                           | int          | Randomization seed. Use this to make learner behaviour           |</span>
<span class="sd">    |                                |              | deterministic.                                                   |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **keras**                                                                                                        |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | backend                        | string       | Keras backend selector.                                          |</span>
<span class="sd">    |                                | {theano |    |                                                                  |</span>
<span class="sd">    |                                | tensorflow}  |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **keras-&gt;backend_parameters**                                                                                    |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | device                         | string       | Device selector. ``cpu`` is best option to produce deterministic |</span>
<span class="sd">    |                                | {cpu | gpu}  | results. All baseline results are calculated in cpu mode.        |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | floatX                         | string       | Float number type. Usually float32 used since that is compatible |</span>
<span class="sd">    |                                |              | with GPUs. Valid only for ``theano`` backend.                    |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | fastmath                       | bool         | If true, will enable fastmath mode when CUDA code is compiled.   |</span>
<span class="sd">    |                                |              | Div and sqrt are faster, but precision is lower. This can cause  |</span>
<span class="sd">    |                                |              | numerical issues some in cases. Valid only for ``theano``        |</span>
<span class="sd">    |                                |              | backend and GPU mode.                                            |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | optimizer                      | string       | Compilation mode for theano functions.                           |</span>
<span class="sd">    |                                | {fast_run |  |                                                                  |</span>
<span class="sd">    |                                | merge |      |                                                                  |</span>
<span class="sd">    |                                | fast_compile |                                                                  |</span>
<span class="sd">    |                                | None}        |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | openmp                         | bool         | If true, Theano will use multiple cores, see `more               |</span>
<span class="sd">    |                                |              | &lt;http://deeplearning.net/software/theano/                        |</span>
<span class="sd">    |                                |              | tutorial/multi_cores.html&gt;`_                                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | threads                        | int          | Number of threads used. Use one to disable threading.            |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | CNR                            | bool         | Conditional numerical reproducibility for MKL BLAS. When set to  |</span>
<span class="sd">    |                                |              | True, compatible mode used.                                      |</span>
<span class="sd">    |                                |              | See `more &lt;https://software.intel.com/en-us/node/528408&gt;`_.      |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **validation**                                                                                                   |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | enable                         | bool         | If true, validation set is used during the training procedure.   |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | setup_source                   | string       | Validation setup source. Valid sources:                          |</span>
<span class="sd">    |                                |              |                                                                  |</span>
<span class="sd">    |                                |              | - ``generated_scene_balanced``, balanced based on scene labels,  |</span>
<span class="sd">    |                                |              |   used for Task1.                                                |</span>
<span class="sd">    |                                |              | - ``generated_event_file_balanced``, balanced based on events,   |</span>
<span class="sd">    |                                |              |   used for Task2.                                                |</span>
<span class="sd">    |                                |              | - ``generated_scene_location_event_balanced``, balanced          |</span>
<span class="sd">    |                                |              |   based on scene, location and events. Used for Task3.           |</span>
<span class="sd">    |                                |              |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | validation_amount              | float        | Percentage of training data selected for validation. Use value   |</span>
<span class="sd">    |                                |              | between 0.0-1.0.                                                 |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | seed                           | int          | Validation set generation seed. If None, learner seed will be    |</span>
<span class="sd">    |                                |              | used.                                                            |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **training**                                                                                                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | epochs                         | int          | Number of epochs.                                                |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | batch_size                     | int          | Batch size.                                                      |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | shuffle                        | bool         | If true, training samples are shuffled at each epoch.            |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **training-&gt;callbacks**, list of parameter sets in following format. Callback called during the model training.  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | type                           | string       | Callback name, use standard keras callbacks                      |</span>
<span class="sd">    |                                |              | `callbacks &lt;https://keras.io/callbacks/&gt;`_ or ones defined by    |</span>
<span class="sd">    |                                |              | dcase_framework (Plotter, Stopper, Stasher).                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | parameters                     | dict         | Place inside this all parameters for the callback.               |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **training-&gt;model-&gt;config**, list of dicts. Defining network topology.                                           |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | class_name                     | string       | Layer name. Use standard keras                                   |</span>
<span class="sd">    |                                |              | `core layers &lt;https://keras.io/layers/core/&gt;`_,                  |</span>
<span class="sd">    |                                |              | `convolutional                                                   |</span>
<span class="sd">    |                                |              | layers &lt;https://keras.io/layers/convolutional/&gt;`_,               |</span>
<span class="sd">    |                                |              | `pooling layers &lt;https://keras.io/layers/pooling/&gt;`_,            |</span>
<span class="sd">    |                                |              | `recurrent layers &lt;https://keras.io/layers/recurrent/&gt;`_, or     |</span>
<span class="sd">    |                                |              | `normalization layers &lt;https://keras.io/layers/normalization/&gt;`_ |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | config                         | dict         | Place inside this all parameters for the layer.                  |</span>
<span class="sd">    |                                |              | See Keras documentation. Magic parameter values:                 |</span>
<span class="sd">    |                                |              |                                                                  |</span>
<span class="sd">    |                                |              | - ``FEATURE_VECTOR_LENGTH``, feature vector length.              |</span>
<span class="sd">    |                                |              |   This automatically inserted for input layer.                   |</span>
<span class="sd">    |                                |              | - ``CLASS_COUNT``, number of classes.                            |</span>
<span class="sd">    |                                |              |                                                                  |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | input_shape                    | list of      | List of integers which is converted into tuple before giving to  |</span>
<span class="sd">    |                                | ints         | Keras layer.                                                     |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **training-&gt;model**                                                                                              |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | loss                           | string       | Keras loss function name. See                                    |</span>
<span class="sd">    |                                |              | `Keras documentation &lt;https://keras.io/losses/&gt;`_.               |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | metrics                        | list of      | Keras metric function name. See                                  |</span>
<span class="sd">    |                                | strings      | `Keras documentation &lt;https://keras.io/metrics/&gt;`_.              |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | **training-&gt;model-&gt;optimizer**                                                                                   |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | type                           | string       | Keras optimizer name. See                                        |</span>
<span class="sd">    |                                |              | `Keras documentation &lt;https://keras.io/optimizers/&gt;`_.           |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>
<span class="sd">    | parameters                     | dict         | Place inside this all parameters for the optimizer.              |</span>
<span class="sd">    +--------------------------------+--------------+------------------------------------------------------------------+</span>

<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="SceneClassifierMLP.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierMLP.html#dcase_framework.learners.SceneClassifierMLP.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;show_model_information&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;audio_error_handling&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.1</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;mlp&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;seed&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;keras&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;backend&#39;</span><span class="p">:</span> <span class="s1">&#39;theano&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;backend_parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                        <span class="s1">&#39;CNR&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                        <span class="s1">&#39;device&#39;</span><span class="p">:</span> <span class="s1">&#39;cpu&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;fastmath&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
                        <span class="s1">&#39;floatX&#39;</span><span class="p">:</span> <span class="s1">&#39;float64&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;openmp&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
                        <span class="s1">&#39;optimizer&#39;</span><span class="p">:</span> <span class="s1">&#39;None&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;threads&#39;</span><span class="p">:</span> <span class="mi">1</span>
                    <span class="p">}</span>
                <span class="p">},</span>
                <span class="s1">&#39;model&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">[</span>
                        <span class="p">{</span>
                            <span class="s1">&#39;class_name&#39;</span><span class="p">:</span> <span class="s1">&#39;Dense&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">{</span>
                                <span class="s1">&#39;activation&#39;</span><span class="p">:</span> <span class="s1">&#39;relu&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;kernel_initializer&#39;</span><span class="p">:</span> <span class="s1">&#39;uniform&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;units&#39;</span><span class="p">:</span> <span class="mi">50</span>
                            <span class="p">}</span>
                        <span class="p">},</span>
                        <span class="p">{</span>
                            <span class="s1">&#39;class_name&#39;</span><span class="p">:</span> <span class="s1">&#39;Dense&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">{</span>
                                <span class="s1">&#39;activation&#39;</span><span class="p">:</span> <span class="s1">&#39;softmax&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;kernel_initializer&#39;</span><span class="p">:</span> <span class="s1">&#39;uniform&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;units&#39;</span><span class="p">:</span> <span class="s1">&#39;CLASS_COUNT&#39;</span>
                            <span class="p">}</span>
                        <span class="p">}</span>
                    <span class="p">],</span>
                    <span class="s1">&#39;loss&#39;</span><span class="p">:</span> <span class="s1">&#39;categorical_crossentropy&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;metrics&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;categorical_accuracy&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;optimizer&#39;</span><span class="p">:</span> <span class="p">{</span>
                        <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;Adam&#39;</span>
                    <span class="p">}</span>
                <span class="p">},</span>
                <span class="s1">&#39;training&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;batch_size&#39;</span><span class="p">:</span> <span class="mi">256</span><span class="p">,</span>
                    <span class="s1">&#39;epochs&#39;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
                    <span class="s1">&#39;shuffle&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                    <span class="s1">&#39;callbacks&#39;</span><span class="p">:</span> <span class="p">[],</span>
                <span class="p">},</span>
                <span class="s1">&#39;validation&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;enable&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                    <span class="s1">&#39;setup_source&#39;</span><span class="p">:</span> <span class="s1">&#39;generated_scene_balanced&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;validation_amount&#39;</span><span class="p">:</span> <span class="mf">0.1</span>
                <span class="p">}</span>
            <span class="p">}</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">SceneClassifierMLP</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;mlp&#39;</span></div>

<div class="viewcode-block" id="SceneClassifierMLP.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierMLP.learn.html#dcase_framework.learners.SceneClassifierMLP.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">validation_files</span><span class="o">=</span><span class="p">[],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>
<span class="sd">        validation_files: list of filenames</span>
<span class="sd">            Predefined validation files, use parameter &#39;validation.setup_source=dataset&#39; to use them.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>  <span class="c1"># Collect training files</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;generated&#39;</span><span class="p">):</span>
                <span class="n">validation_files</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_generate_validation</span><span class="p">(</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">validation_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">),</span>
                    <span class="n">valid_percentage</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.validation_amount&#39;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">),</span>
                    <span class="n">seed</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.seed&#39;</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;dataset&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                    <span class="n">validation_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">training_files</span><span class="p">)))</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No validation_files set&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                    <span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation.setup_source [</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span>
                <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Double check that training and validation files are not overlapping.</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">validation_files</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Training and validation file lists are overlapping!&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Convert annotations into activity matrix format</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">)</span>

        <span class="c1"># Process data</span>
        <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">)</span>
        <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Training items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{examples:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">examples</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">X_training</span><span class="p">)))</span>

        <span class="c1"># Process validation data</span>
        <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
            <span class="n">X_validation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">)</span>
            <span class="n">Y_validation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">)</span>

            <span class="n">validation</span> <span class="o">=</span> <span class="p">(</span><span class="n">X_validation</span><span class="p">,</span> <span class="n">Y_validation</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Validation items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{validation:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">validation</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">X_validation</span><span class="p">)))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="c1"># Setup Keras</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_setup_keras</span><span class="p">()</span>

        <span class="k">with</span> <span class="n">SuppressStdoutAndStderr</span><span class="p">():</span>
            <span class="c1"># Import keras and suppress backend announcement printed to stderr</span>
            <span class="kn">import</span> <span class="nn">keras</span>

        <span class="c1"># Create model</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">create_model</span><span class="p">(</span><span class="n">input_shape</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_input_size</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_model_summary</span><span class="p">()</span>

        <span class="c1"># Create callbacks</span>
        <span class="n">callback_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_callback_list</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Feature vector </span><span class="se">\t</span><span class="s1">[</span><span class="si">{vector:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">vector</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_input_size</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Batch size </span><span class="se">\t</span><span class="s1">[</span><span class="si">{batch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">batch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epochs </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{epoch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
            <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
            <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
            <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
            <span class="n">epochs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
            <span class="n">validation_data</span><span class="o">=</span><span class="n">validation</span><span class="p">,</span>
            <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
            <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
            <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span>
        <span class="p">)</span>

        <span class="c1"># Manually update callbacks</span>
        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">StasherCallback</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
                <span class="n">best_weights</span> <span class="o">=</span> <span class="n">callback</span><span class="o">.</span><span class="n">get_best</span><span class="p">()[</span><span class="s1">&#39;weights&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">best_weights</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">set_weights</span><span class="p">(</span><span class="n">best_weights</span><span class="p">)</span>
                <span class="k">break</span>

        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;learning_history&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span></div>

    <span class="k">def</span> <span class="nf">_frame_probabilities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span></div>


<div class="viewcode-block" id="SceneClassifierKerasSequential"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.html#dcase_framework.learners.SceneClassifierKerasSequential">[docs]</a><span class="k">class</span> <span class="nc">SceneClassifierKerasSequential</span><span class="p">(</span><span class="n">SceneClassifierMLP</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sequential Keras model for Acoustic scene classification&quot;&quot;&quot;</span>
<div class="viewcode-block" id="SceneClassifierKerasSequential.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.html#dcase_framework.learners.SceneClassifierKerasSequential.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">SceneClassifierKerasSequential</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;keras_seq&#39;</span>

        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;training_data_processor&#39;</span><span class="p">,</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_generators&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">data_generator_list</span> <span class="o">=</span> <span class="n">get_class_inheritors</span><span class="p">(</span><span class="n">BaseDataGenerator</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">data_generator_item</span> <span class="ow">in</span> <span class="n">data_generator_list</span><span class="p">:</span>
                <span class="n">generator</span> <span class="o">=</span> <span class="n">data_generator_item</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">generator</span><span class="o">.</span><span class="n">method</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="n">generator</span><span class="o">.</span><span class="n">method</span><span class="p">]</span> <span class="o">=</span> <span class="n">data_generator_item</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">data_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature processing chain</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">         feature_processing_chain</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@data_processor</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">data_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">data_processor_training</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature processing chain</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">         feature_processing_chain</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@data_processor_training</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">data_processor_training</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="SceneClassifierKerasSequential.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.learn.html#dcase_framework.learners.SceneClassifierKerasSequential.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">validation_files</span><span class="o">=</span><span class="p">[],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>
<span class="sd">        validation_files: list of filenames</span>
<span class="sd">            Predefined validation files, use parameter &#39;validation.setup_source=dataset&#39; to use them.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifting.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
           <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
           <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)):</span>

            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Temporal shifting cannot be used. Use epoch_processing or generator to allow temporal shifting of data.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Collect training files</span>
        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>

        <span class="c1"># Validation files</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;generated&#39;</span><span class="p">):</span>
                <span class="n">validation_files</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_generate_validation</span><span class="p">(</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">validation_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">),</span>
                    <span class="n">valid_percentage</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.validation_amount&#39;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">),</span>
                    <span class="n">seed</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.seed&#39;</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;dataset&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                    <span class="n">validation_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">training_files</span><span class="p">)))</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No validation_files set&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                    <span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation.setup_source [</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span>
                <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Double check that training and validation files are not overlapping.</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">validation_files</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Training and validation file lists are overlapping!&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="c1"># Setup Keras</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_setup_keras</span><span class="p">()</span>

        <span class="k">with</span> <span class="n">SuppressStdoutAndStderr</span><span class="p">():</span>
            <span class="c1"># Import keras and suppress backend announcement printed to stderr</span>
            <span class="kn">import</span> <span class="nn">keras</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
            <span class="c1"># Create generators</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">:</span>
                <span class="n">training_data_generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)](</span>
                    <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                    <span class="n">data_filenames</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">,</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">data_processor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_processor_training</span><span class="p">,</span>
                    <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                    <span class="n">hop_length_seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">),</span>
                    <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                    <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">data_refresh_on_each_epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifting.enable&#39;</span><span class="p">),</span>
                    <span class="n">label_mode</span><span class="o">=</span><span class="s1">&#39;scene&#39;</span><span class="p">,</span>
                    <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.parameters&#39;</span><span class="p">,</span> <span class="p">{})</span>
                <span class="p">)</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
                    <span class="n">validation_data_generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)](</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">data_filenames</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">,</span>
                        <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                        <span class="n">data_processor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="p">,</span>
                        <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                        <span class="n">hop_length_seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">),</span>
                        <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                        <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">label_mode</span><span class="o">=</span><span class="s1">&#39;scene&#39;</span><span class="p">,</span>
                        <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.parameters&#39;</span><span class="p">,</span> <span class="p">{})</span>
                    <span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">validation_data_generator</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Generator method not implemented [</span><span class="si">{method}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">method</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">input_shape</span> <span class="o">=</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">input_size</span>
            <span class="n">training_data_size</span> <span class="o">=</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">data_size</span>
            <span class="k">if</span> <span class="n">validation_data_generator</span><span class="p">:</span>
                <span class="n">validation_data_size</span> <span class="o">=</span> <span class="n">validation_data_generator</span><span class="o">.</span><span class="n">data_size</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Convert annotations into activity matrix format</span>
            <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>

            <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
            <span class="p">)</span>
            <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                <span class="n">validation_data</span> <span class="o">=</span> <span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                        <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;default&#39;</span>
                    <span class="p">),</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                        <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;default&#39;</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="n">validation_data_size</span> <span class="o">=</span> <span class="n">validation_data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

            <span class="n">input_shape</span> <span class="o">=</span> <span class="n">X_training</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">training_data_size</span> <span class="o">=</span> <span class="n">X_training</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Create model</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">create_model</span><span class="p">(</span><span class="n">input_shape</span><span class="o">=</span><span class="n">input_shape</span><span class="p">)</span>

        <span class="c1"># Get processing interval</span>
        <span class="n">processing_interval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_processing_interval</span><span class="p">()</span>

        <span class="c1"># Create callbacks</span>
        <span class="n">callback_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_callback_list</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_model_summary</span><span class="p">()</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Files&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span>
                <span class="s1">&#39;    Training </span><span class="se">\t</span><span class="s1">[</span><span class="si">{examples:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">examples</span><span class="o">=</span><span class="n">training_data_size</span><span class="p">)</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span>
                    <span class="s1">&#39;    Validation </span><span class="se">\t</span><span class="s1">[</span><span class="si">{validation:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">validation</span><span class="o">=</span><span class="n">validation_data_size</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Input&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Feature vector </span><span class="se">\t</span><span class="s1">[</span><span class="si">{vector:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">vector</span><span class="o">=</span><span class="n">input_shape</span><span class="p">)</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.enable&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Sequence</span><span class="se">\t</span><span class="s1">[</span><span class="si">{length:d}</span><span class="s1">]</span><span class="se">\t\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">length</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.frames&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.frames&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)):</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Sequence shifting per epoch&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Shift </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{step:d}</span><span class="s1"> per epoch]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">step</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.step&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.step&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Max </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{max:d}</span><span class="s1"> per epoch]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="nb">max</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.max&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.max&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Border </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{border:s}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">border</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.border&#39;</span><span class="p">,</span> <span class="s1">&#39;roll&#39;</span><span class="p">)</span>
                <span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Batch size </span><span class="se">\t</span><span class="s1">[</span><span class="si">{batch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">batch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epochs </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{epoch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="c1"># Extra info about training</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">training_data_generator</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">info</span><span class="p">():</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epoch processing </span><span class="se">\t</span><span class="s1">[</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;Epoch-by-Epoch&#39;</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epoch processing </span><span class="se">\t</span><span class="s1">[</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;Keras&#39;</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.enable&#39;</span><span class="p">)):</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  External metrics&#39;</span><span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Metrics</span><span class="se">\t\t</span><span class="s1">Label</span><span class="se">\t</span><span class="s1">Evaluator:Name&#39;</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.metrics&#39;</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{label}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">[</span><span class="si">{metric}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">label</span><span class="o">=</span><span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;label&#39;</span><span class="p">),</span>
                        <span class="n">metric</span><span class="o">=</span><span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;evaluator&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;:&#39;</span> <span class="o">+</span> <span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">))</span>
                    <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Interval </span><span class="se">\t</span><span class="s1">[</span><span class="si">{processing_interval:d}</span><span class="s1"> epochs]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">processing_interval</span><span class="o">=</span><span class="n">processing_interval</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="n">epochs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

        <span class="c1"># Initialize training history</span>
        <span class="n">learning_history</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;loss&#39;</span><span class="p">:</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,)),</span>
            <span class="s1">&#39;val_loss&#39;</span><span class="p">:</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,)),</span>
        <span class="p">}</span>
        <span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">metrics</span><span class="p">:</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="n">metric</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="s1">&#39;val_&#39;</span><span class="o">+</span><span class="n">metric</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
        <span class="k">for</span> <span class="n">quantity</span> <span class="ow">in</span> <span class="n">learning_history</span><span class="p">:</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="n">quantity</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">):</span>
            <span class="c1"># Get external metric evaluators</span>
            <span class="n">external_metric_evaluators</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_external_metric_evaluators</span><span class="p">()</span>

            <span class="k">for</span> <span class="n">external_metric_id</span> <span class="ow">in</span> <span class="n">external_metric_evaluators</span><span class="p">:</span>
                <span class="n">metric_label</span> <span class="o">=</span> <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;label&#39;</span><span class="p">]</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

            <span class="k">for</span> <span class="n">epoch_start</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">processing_interval</span><span class="p">):</span>
                <span class="c1"># Last epoch</span>
                <span class="n">epoch_end</span> <span class="o">=</span> <span class="n">epoch_start</span> <span class="o">+</span> <span class="n">processing_interval</span>
                <span class="c1"># Make sure we have only specified amount of epochs</span>
                <span class="k">if</span> <span class="n">epoch_end</span> <span class="o">&gt;</span> <span class="n">epochs</span><span class="p">:</span>
                    <span class="n">epoch_end</span> <span class="o">=</span> <span class="n">epochs</span>

                <span class="c1"># Model fitting</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                    <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit_generator</span><span class="p">(</span>
                        <span class="n">generator</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                        <span class="n">steps_per_epoch</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                        <span class="n">initial_epoch</span><span class="o">=</span><span class="n">epoch_start</span><span class="p">,</span>
                        <span class="n">epochs</span><span class="o">=</span><span class="n">epoch_end</span><span class="p">,</span>
                        <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                        <span class="n">validation_steps</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                        <span class="n">max_queue_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.max_q_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">workers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.workers&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                        <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span>
                    <span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                        <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
                        <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
                        <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">initial_epoch</span><span class="o">=</span><span class="n">epoch_start</span><span class="p">,</span>
                        <span class="n">epochs</span><span class="o">=</span><span class="n">epoch_end</span><span class="p">,</span>
                        <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data</span><span class="p">,</span>
                        <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                        <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                        <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span>
                    <span class="p">)</span>

                <span class="c1"># Store keras metrics into learning history log</span>
                <span class="k">for</span> <span class="n">keras_metric</span> <span class="ow">in</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">:</span>
                    <span class="n">learning_history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">][</span><span class="n">epoch_start</span><span class="p">:</span><span class="n">epoch_start</span><span class="o">+</span><span class="nb">len</span><span class="p">(</span><span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">])]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">]</span>

                <span class="c1"># Evaluate validation data with external metrics</span>
                <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
                   <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.enable&#39;</span><span class="p">)):</span>

                    <span class="c1"># Recognizer class</span>
                    <span class="n">recognizer</span> <span class="o">=</span> <span class="n">SceneRecognizer</span><span class="p">(</span>
                        <span class="n">params</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.recognizer&#39;</span><span class="p">),</span>
                        <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span>
                    <span class="p">)</span>

                    <span class="k">for</span> <span class="n">external_metric_id</span> <span class="ow">in</span> <span class="n">external_metric_evaluators</span><span class="p">:</span>
                        <span class="c1"># Reset evaluators</span>
                        <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>

                        <span class="n">metric_label</span> <span class="o">=</span> <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;label&#39;</span><span class="p">]</span>

                        <span class="c1"># Evaluate validation data</span>
                        <span class="k">for</span> <span class="n">validation_file</span> <span class="ow">in</span> <span class="n">validation_files</span><span class="p">:</span>
                            <span class="c1"># Get feature data</span>
                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                                <span class="n">feature_data</span><span class="p">,</span> <span class="n">feature_data_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="o">.</span><span class="n">load</span><span class="p">(</span>
                                    <span class="n">feature_filename_dict</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]</span>
                                <span class="p">)</span>

                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">feature_data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]</span>

                            <span class="c1"># Predict</span>
                            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">feature_data</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span>

                            <span class="n">predicted</span> <span class="o">=</span> <span class="p">[</span>
                                <span class="n">MetaDataItem</span><span class="p">(</span>
                                    <span class="p">{</span>
                                        <span class="s1">&#39;file&#39;</span><span class="p">:</span> <span class="n">validation_file</span><span class="p">,</span>
                                        <span class="s1">&#39;scene_label&#39;</span><span class="p">:</span> <span class="n">recognizer</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">frame_probabilities</span><span class="o">=</span><span class="n">frame_probabilities</span><span class="p">),</span>
                                    <span class="p">}</span>
                                <span class="p">)</span>
                            <span class="p">]</span>

                            <span class="c1"># Get reference data</span>
                            <span class="n">meta</span> <span class="o">=</span> <span class="p">[</span>
                                <span class="n">annotations</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]</span>
                            <span class="p">]</span>

                            <span class="c1"># Evaluate</span>
                            <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">evaluate</span><span class="p">(</span>
                                <span class="n">meta</span><span class="p">,</span>
                                <span class="n">predicted</span>
                            <span class="p">)</span>

                        <span class="c1"># Get metric value</span>
                        <span class="n">metric_value</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">(</span>
                            <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">results</span><span class="p">()</span>
                        <span class="p">)</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;path&#39;</span><span class="p">])</span>

                        <span class="k">if</span> <span class="n">metric_value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Metric was not found, evaluator:[</span><span class="si">{evaluator}</span><span class="s1">] metric:[</span><span class="si">{metric}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                                <span class="n">evaluator</span><span class="o">=</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">],</span>
                                <span class="n">metric</span><span class="o">=</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;path&#39;</span><span class="p">]</span>
                            <span class="p">)</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

                        <span class="c1"># Inject external metric values to the callbacks</span>
                        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;set_external_metric_value&#39;</span><span class="p">):</span>
                                <span class="n">callback</span><span class="o">.</span><span class="n">set_external_metric_value</span><span class="p">(</span>
                                    <span class="n">metric_label</span><span class="o">=</span><span class="n">metric_label</span><span class="p">,</span>
                                    <span class="n">metric_value</span><span class="o">=</span><span class="n">metric_value</span>
                                <span class="p">)</span>

                        <span class="c1"># Store metric value into learning history log</span>
                        <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">][</span><span class="n">epoch_end</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">metric_value</span>

                <span class="c1"># Manually update callbacks</span>
                <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;update&#39;</span><span class="p">):</span>
                        <span class="n">callback</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>

                <span class="c1"># Check we need to stop training</span>
                <span class="n">stop_training</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;stop&#39;</span><span class="p">):</span>
                        <span class="k">if</span> <span class="n">callback</span><span class="o">.</span><span class="n">stop</span><span class="p">():</span>
                            <span class="n">stop_training</span> <span class="o">=</span> <span class="kc">True</span>

                <span class="k">if</span> <span class="n">stop_training</span><span class="p">:</span>
                    <span class="c1"># Stop the training loop</span>
                    <span class="k">break</span>

                <span class="c1"># Training data processing between epochs</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.enable&#39;</span><span class="p">):</span>
                    <span class="c1"># Increase temporal shifting</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_processor_training</span><span class="o">.</span><span class="n">call_method</span><span class="p">(</span><span class="s1">&#39;increase_shifting&#39;</span><span class="p">)</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                        <span class="c1"># Refresh training data manually with new parameters</span>
                        <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                            <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                            <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                            <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
                        <span class="p">)</span>

                        <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                            <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                            <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                            <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
                        <span class="p">)</span>


        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit_generator</span><span class="p">(</span>
                    <span class="n">generator</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                    <span class="n">steps_per_epoch</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                    <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span>
                    <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                    <span class="n">validation_steps</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                    <span class="n">max_queue_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.max_q_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">workers</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span>
                <span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
                    <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
                    <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span>
                    <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data</span><span class="p">,</span>
                    <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                    <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span>
                <span class="p">)</span>

            <span class="c1"># Store keras metrics into learning history log</span>
            <span class="k">for</span> <span class="n">keras_metric</span> <span class="ow">in</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">:</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">])]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">]</span>

        <span class="c1"># Manually update callbacks</span>
        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">StasherCallback</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
                <span class="n">best_weights</span> <span class="o">=</span> <span class="n">callback</span><span class="o">.</span><span class="n">get_best</span><span class="p">()[</span><span class="s1">&#39;weights&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">best_weights</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">set_weights</span><span class="p">(</span><span class="n">best_weights</span><span class="p">)</span>
                <span class="k">break</span>

        <span class="c1"># Store learning history to the model</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;learning_history&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">learning_history</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="SceneClassifierKerasSequential.predict"><a class="viewcode-back" href="../../generated/dcase_framework.learners.SceneClassifierKerasSequential.predict.html#dcase_framework.learners.SceneClassifierKerasSequential.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Predict frame probabilities for given feature matrix</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        feature_data : numpy.ndarray</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        numpy.ndarray</span>
<span class="sd">            Frame probabilities</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="n">FeatureContainer</span><span class="p">):</span>
            <span class="c1"># If we have featureContainer as input, get feature_data</span>
            <span class="n">feature_data</span> <span class="o">=</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="p">:</span>
            <span class="c1"># Feature repository given, and feature processor present</span>
            <span class="n">feature_data</span><span class="p">,</span> <span class="n">feature_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">feature_data</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span>

        <span class="c1"># Get frame wise probabilities</span>
        <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">4</span><span class="p">:</span>
                <span class="c1"># Still feature data in wrong shape, trying to recover</span>
                <span class="n">data_sequencer</span> <span class="o">=</span> <span class="n">DataSequencer</span><span class="p">(</span>
                    <span class="n">frames</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                    <span class="n">hop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                <span class="p">)</span>

                <span class="n">feature_data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">expand_dims</span><span class="p">(</span><span class="n">data_sequencer</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">feature_data</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

            <span class="c1"># Join sequences</span>
            <span class="c1"># TODO: if data_sequencer.hop != data_sequencer.frames, do additional processing here.</span>
            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span>
                <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="p">)</span>

        <span class="k">return</span> <span class="n">frame_probabilities</span></div></div>


<div class="viewcode-block" id="EventDetector"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetector.html#dcase_framework.learners.EventDetector">[docs]</a><span class="k">class</span> <span class="nc">EventDetector</span><span class="p">(</span><span class="n">LearnerContainer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Event detector (Frame classifier / Multi-class - Multi-label)&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">_get_target_matrix_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">):</span>

        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
            <span class="c1"># Create event roll</span>
            <span class="n">event_roll</span> <span class="o">=</span> <span class="n">EventRoll</span><span class="p">(</span><span class="n">metadata_container</span><span class="o">=</span><span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">],</span>
                                   <span class="n">label_list</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                                   <span class="n">time_resolution</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                                   <span class="p">)</span>
            <span class="c1"># Pad event roll to full length of the signal</span>
            <span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span> <span class="o">=</span> <span class="n">event_roll</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">length</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">activity_matrix_dict</span>

    <span class="k">def</span> <span class="nf">_generate_validation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">validation_type</span><span class="o">=</span><span class="s1">&#39;generated_scene_location_event_balanced&#39;</span><span class="p">,</span>
                             <span class="n">valid_percentage</span><span class="o">=</span><span class="mf">0.20</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">(</span><span class="n">seed</span><span class="o">=</span><span class="n">seed</span><span class="p">)</span>
        <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Validation&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">validation_type</span> <span class="o">==</span> <span class="s1">&#39;generated_scene_location_event_balanced&#39;</span><span class="p">:</span>
            <span class="c1"># Get training data per scene label</span>
            <span class="n">annotation_data</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
                <span class="n">scene_label</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">scene_label</span>
                <span class="n">location_id</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">identifier</span>
                <span class="k">if</span> <span class="n">scene_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">annotation_data</span><span class="p">:</span>
                    <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">if</span> <span class="n">location_id</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]:</span>
                    <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">audio_filename</span><span class="p">)</span>

            <span class="c1"># Get event amounts</span>
            <span class="n">event_amounts</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">scene_label</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">annotation_data</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                <span class="k">if</span> <span class="n">scene_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">event_amounts</span><span class="p">:</span>
                    <span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">location_id</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                    <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">location_id</span><span class="p">]:</span>
                        <span class="n">current_event_amounts</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">event_stat_counts</span><span class="p">()</span>
                        <span class="k">for</span> <span class="n">event_label</span><span class="p">,</span> <span class="n">count</span> <span class="ow">in</span> <span class="n">iteritems</span><span class="p">(</span><span class="n">current_event_amounts</span><span class="p">):</span>
                            <span class="k">if</span> <span class="n">event_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]:</span>
                                <span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">event_label</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
                            <span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">event_label</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>

            <span class="k">for</span> <span class="n">scene_label</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">annotation_data</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                <span class="c1"># Optimize scene sets separately</span>
                <span class="n">validation_set_candidates</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">validation_set_MAE</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">validation_set_event_amounts</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">training_set_event_amounts</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1000</span><span class="p">):</span>
                    <span class="n">location_ids</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
                    <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">location_ids</span><span class="p">,</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">)</span>

                    <span class="n">valid_percentage_index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">valid_percentage</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">location_ids</span><span class="p">)))</span>

                    <span class="n">current_validation_files</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">loc_id</span> <span class="ow">in</span> <span class="n">location_ids</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">valid_percentage_index</span><span class="p">]:</span>
                        <span class="n">current_validation_files</span> <span class="o">+=</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">loc_id</span><span class="p">]</span>

                    <span class="n">current_training_files</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">loc_id</span> <span class="ow">in</span> <span class="n">location_ids</span><span class="p">[</span><span class="n">valid_percentage_index</span><span class="p">:]:</span>
                        <span class="n">current_training_files</span> <span class="o">+=</span> <span class="n">annotation_data</span><span class="p">[</span><span class="n">scene_label</span><span class="p">][</span><span class="n">loc_id</span><span class="p">]</span>

                    <span class="c1"># event count in training set candidate</span>
                    <span class="n">training_set_event_counts</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]))</span>
                    <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="n">current_training_files</span><span class="p">:</span>
                        <span class="n">current_event_amounts</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">event_stat_counts</span><span class="p">()</span>
                        <span class="k">for</span> <span class="n">event_label_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]):</span>
                            <span class="k">if</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="n">current_event_amounts</span><span class="p">:</span>
                                <span class="n">training_set_event_counts</span><span class="p">[</span><span class="n">event_label_id</span><span class="p">]</span> <span class="o">+=</span> <span class="n">current_event_amounts</span><span class="p">[</span><span class="n">event_label</span><span class="p">]</span>

                    <span class="c1"># Accept only sets which leave at least one example for training</span>
                    <span class="k">if</span> <span class="n">numpy</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">training_set_event_counts</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">):</span>
                        <span class="c1"># event counts in validation set candidate</span>
                        <span class="n">validation_set_event_counts</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]))</span>
                        <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="n">current_validation_files</span><span class="p">:</span>
                            <span class="n">current_event_amounts</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">event_stat_counts</span><span class="p">()</span>

                            <span class="k">for</span> <span class="n">event_label_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]):</span>
                                <span class="k">if</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="n">current_event_amounts</span><span class="p">:</span>
                                    <span class="n">validation_set_event_counts</span><span class="p">[</span><span class="n">event_label_id</span><span class="p">]</span> <span class="o">+=</span> <span class="n">current_event_amounts</span><span class="p">[</span><span class="n">event_label</span><span class="p">]</span>

                        <span class="c1"># Accept only sets which have examples from each sound event class</span>
                        <span class="k">if</span> <span class="n">numpy</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">validation_set_event_counts</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">):</span>
                            <span class="n">validation_amount</span> <span class="o">=</span> <span class="n">validation_set_event_counts</span> <span class="o">/</span> <span class="p">(</span><span class="n">validation_set_event_counts</span> <span class="o">+</span> <span class="n">training_set_event_counts</span><span class="p">)</span>
                            <span class="n">validation_set_candidates</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">current_validation_files</span><span class="p">)</span>
                            <span class="n">validation_set_MAE</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mean_absolute_error</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">validation_amount</span><span class="p">))</span> <span class="o">*</span> <span class="n">valid_percentage</span><span class="p">,</span> <span class="n">validation_amount</span><span class="p">))</span>
                            <span class="n">validation_set_event_amounts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">validation_set_event_counts</span><span class="p">)</span>
                            <span class="n">training_set_event_amounts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">training_set_event_counts</span><span class="p">)</span>

                <span class="c1"># Generate balance validation set</span>
                <span class="c1"># Selection done based on event counts (per scene class)</span>
                <span class="c1"># Target count specified percentage of training event count</span>
                <span class="k">if</span> <span class="n">validation_set_MAE</span><span class="p">:</span>
                    <span class="n">best_set_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">validation_set_MAE</span><span class="p">)</span>
                    <span class="n">validation_files</span> <span class="o">+=</span> <span class="n">validation_set_candidates</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">]</span>

                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Valid sets found [</span><span class="si">{sets}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="n">sets</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">validation_set_MAE</span><span class="p">))</span>
                        <span class="p">)</span>

                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Best fitting set ID=</span><span class="si">{id}</span><span class="s1">, Error=</span><span class="si">{error:4.2}</span><span class="s1">%&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="nb">id</span><span class="o">=</span><span class="n">best_set_id</span><span class="p">,</span>
                            <span class="n">error</span><span class="o">=</span><span class="n">validation_set_MAE</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">]</span><span class="o">*</span><span class="mi">100</span><span class="p">)</span>
                        <span class="p">)</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Validation event counts in respect of all data:&#39;</span><span class="p">)</span>
                        <span class="n">event_amount_percentages</span> <span class="o">=</span> <span class="n">validation_set_event_amounts</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">validation_set_event_amounts</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">]</span> <span class="o">+</span> <span class="n">training_set_event_amounts</span><span class="p">[</span><span class="n">best_set_id</span><span class="p">])</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event:&lt;20s}</span><span class="s1"> | </span><span class="si">{amount:10s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="n">event</span><span class="o">=</span><span class="s1">&#39;Event label&#39;</span><span class="p">,</span>
                            <span class="n">amount</span><span class="o">=</span><span class="s1">&#39;Amount (%)&#39;</span><span class="p">)</span>
                        <span class="p">)</span>

                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event:&lt;20s}</span><span class="s1"> + </span><span class="si">{amount:10s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="n">event</span><span class="o">=</span><span class="s1">&#39;-&#39;</span> <span class="o">*</span> <span class="mi">20</span><span class="p">,</span>
                            <span class="n">amount</span><span class="o">=</span><span class="s1">&#39;-&#39;</span> <span class="o">*</span> <span class="mi">20</span><span class="p">)</span>
                        <span class="p">)</span>

                        <span class="k">for</span> <span class="n">event_label_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">scene_label</span><span class="p">]):</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event:&lt;20s}</span><span class="s1"> | </span><span class="si">{amount:4.2f}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                <span class="n">event</span><span class="o">=</span><span class="n">event_label</span><span class="p">,</span>
                                <span class="n">amount</span><span class="o">=</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">event_amount_percentages</span><span class="p">[</span><span class="n">event_label_id</span><span class="p">]</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))</span>
                            <span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Validation setup creation was not successful! Could not find a set with &#39;</span> \
                              <span class="s1">&#39;examples for each event class in both training and validation.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                              <span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">AssertionError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">validation_type</span> <span class="o">==</span> <span class="s1">&#39;generated_event_file_balanced&#39;</span><span class="p">:</span>
            <span class="c1"># Get event amounts</span>
            <span class="n">event_amounts</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
                <span class="n">event_label</span> <span class="o">=</span> <span class="n">annotations</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">event_label</span>
                <span class="k">if</span> <span class="n">event_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">event_amounts</span><span class="p">:</span>
                    <span class="n">event_amounts</span><span class="p">[</span><span class="n">event_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">event_amounts</span><span class="p">[</span><span class="n">event_label</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">audio_filename</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event_label:&lt;20s}</span><span class="s1"> | </span><span class="si">{amount:20s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">event_label</span><span class="o">=</span><span class="s1">&#39;Event label&#39;</span><span class="p">,</span>
                    <span class="n">amount</span><span class="o">=</span><span class="s1">&#39;Files (%)&#39;</span><span class="p">)</span>
                <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event_label:&lt;20s}</span><span class="s1"> + </span><span class="si">{amount:20s}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">event_label</span><span class="o">=</span><span class="s1">&#39;-&#39;</span> <span class="o">*</span> <span class="mi">20</span><span class="p">,</span>
                    <span class="n">amount</span><span class="o">=</span><span class="s1">&#39;-&#39;</span> <span class="o">*</span> <span class="mi">20</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">def</span> <span class="nf">sorter</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">key</span><span class="p">:</span>
                    <span class="k">return</span> <span class="s2">&quot;&quot;</span>
                <span class="k">return</span> <span class="n">key</span>

            <span class="n">event_label_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">event_amounts</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
            <span class="n">event_label_list</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sorter</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="n">event_label_list</span><span class="p">:</span>
                <span class="n">files</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">event_amounts</span><span class="p">[</span><span class="n">event_label</span><span class="p">]))</span>
                <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">files</span><span class="p">,</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">)</span>
                <span class="n">valid_percentage_index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">valid_percentage</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">)))</span>
                <span class="n">validation_files</span> <span class="o">+=</span> <span class="n">files</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">valid_percentage_index</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">{event_label:&lt;20s}</span><span class="s1"> | </span><span class="si">{amount:4.2f}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">event_label</span><span class="o">=</span><span class="n">event_label</span> <span class="k">if</span> <span class="n">event_label</span> <span class="k">else</span> <span class="s1">&#39;-&#39;</span><span class="p">,</span>
                        <span class="n">amount</span><span class="o">=</span><span class="n">valid_percentage_index</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">))</span> <span class="o">*</span> <span class="mf">100.0</span><span class="p">)</span>
                    <span class="p">)</span>

            <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">validation_files</span><span class="p">,</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation_type [</span><span class="si">{type}</span><span class="s1">].&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="nb">type</span><span class="o">=</span><span class="n">validation_type</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">AssertionError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Implement learn function.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">AssertionError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span></div>


<div class="viewcode-block" id="EventDetectorGMM"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorGMM.html#dcase_framework.learners.EventDetectorGMM">[docs]</a><span class="k">class</span> <span class="nc">EventDetectorGMM</span><span class="p">(</span><span class="n">EventDetector</span><span class="p">):</span>
<div class="viewcode-block" id="EventDetectorGMM.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorGMM.html#dcase_framework.learners.EventDetectorGMM.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;gmm&#39;</span><span class="p">,</span>
            <span class="s1">&#39;scene_handling&#39;</span><span class="p">:</span> <span class="s1">&#39;scene-dependent&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;covariance_type&#39;</span><span class="p">:</span> <span class="s1">&#39;diag&#39;</span><span class="p">,</span>
                <span class="s1">&#39;init_params&#39;</span><span class="p">:</span> <span class="s1">&#39;kmeans&#39;</span><span class="p">,</span>
                <span class="s1">&#39;max_iter&#39;</span><span class="p">:</span> <span class="mi">40</span><span class="p">,</span>
                <span class="s1">&#39;n_components&#39;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                <span class="s1">&#39;n_init&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                <span class="s1">&#39;random_state&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;reg_covar&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;tol&#39;</span><span class="p">:</span> <span class="mf">0.001</span>
            <span class="p">},</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">EventDetectorGMM</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;gmm&#39;</span></div>

<div class="viewcode-block" id="EventDetectorGMM.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorGMM.learn.html#dcase_framework.learners.EventDetectorGMM.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="kn">from</span> <span class="nn">sklearn.mixture</span> <span class="k">import</span> <span class="n">GaussianMixture</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No hop length set.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Validation is not implemented for this learner.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="n">class_progress</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
            <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span>
            <span class="n">leave</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">desc</span><span class="o">=</span><span class="s1">&#39;           </span><span class="si">{0:&gt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Learn &#39;</span><span class="p">),</span>
            <span class="n">bar_format</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">{l_bar}{bar}</span><span class="s1">| </span><span class="si">{n_fmt}</span><span class="s1">/</span><span class="si">{total_fmt}</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># [{elapsed}&lt;{remaining}, {rate_fmt}]&#39;,</span>
            <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">disable_progress_bar</span>
        <span class="p">)</span>

        <span class="c1"># Collect training examples</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">event_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">class_progress</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_progress</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{title:&lt;15s}</span><span class="s1"> [</span><span class="si">{item_id:d}</span><span class="s1">/</span><span class="si">{total:d}</span><span class="s1">] </span><span class="si">{event_label:&lt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Learn&#39;</span><span class="p">,</span>
                    <span class="n">item_id</span><span class="o">=</span><span class="n">event_id</span><span class="p">,</span>
                    <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span>
                    <span class="n">event_label</span><span class="o">=</span><span class="n">event_label</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="n">data_positive</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">data_negative</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
                <span class="n">activity_matrix</span> <span class="o">=</span> <span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span>

                <span class="n">positive_mask</span> <span class="o">=</span> <span class="n">activity_matrix</span><span class="p">[:,</span> <span class="n">event_id</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">bool</span><span class="p">)</span>
                <span class="c1"># Store positive examples</span>
                <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">positive_mask</span><span class="p">):</span>
                    <span class="n">data_positive</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">positive_mask</span><span class="p">,</span> <span class="p">:])</span>

                <span class="c1"># Store negative examples</span>
                <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="o">~</span><span class="n">positive_mask</span><span class="p">):</span>
                    <span class="n">data_negative</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="o">~</span><span class="n">positive_mask</span><span class="p">,</span> <span class="p">:])</span>

            <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s1">&#39;positive&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                <span class="s1">&#39;negative&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="p">}</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_positive</span><span class="p">):</span>
                <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">GaussianMixture</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">data_positive</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_negative</span><span class="p">):</span>
                <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">GaussianMixture</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">data_negative</span><span class="p">)</span>
                <span class="p">)</span></div>

<div class="viewcode-block" id="EventDetectorGMM.predict"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorGMM.predict.html#dcase_framework.learners.EventDetectorGMM.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>

        <span class="n">frame_probabilities_positive</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">frame_probabilities_negative</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">frame_probabilities_positive</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>
        <span class="n">frame_probabilities_negative</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

        <span class="k">for</span> <span class="n">event_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]:</span>
                <span class="n">frame_probabilities_positive</span><span class="p">[</span><span class="n">event_id</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">score_samples</span><span class="p">(</span>
                    <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]:</span>
                <span class="n">frame_probabilities_negative</span><span class="p">[</span><span class="n">event_id</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">score_samples</span><span class="p">(</span>
                    <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="p">)</span>

        <span class="k">return</span> <span class="n">frame_probabilities_positive</span><span class="p">,</span> <span class="n">frame_probabilities_negative</span></div></div>


<span class="k">class</span> <span class="nc">EventDetectorGMMdeprecated</span><span class="p">(</span><span class="n">EventDetector</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;gmm_deprecated&#39;</span><span class="p">,</span>
            <span class="s1">&#39;scene_handling&#39;</span><span class="p">:</span> <span class="s1">&#39;scene-dependent&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;n_components&#39;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                <span class="s1">&#39;covariance_type&#39;</span><span class="p">:</span> <span class="s1">&#39;diag&#39;</span><span class="p">,</span>
                <span class="s1">&#39;random_state&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;tol&#39;</span><span class="p">:</span> <span class="mf">0.001</span><span class="p">,</span>
                <span class="s1">&#39;min_covar&#39;</span><span class="p">:</span> <span class="mf">0.001</span><span class="p">,</span>
                <span class="s1">&#39;n_iter&#39;</span><span class="p">:</span> <span class="mi">40</span><span class="p">,</span>
                <span class="s1">&#39;n_init&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                <span class="s1">&#39;params&#39;</span><span class="p">:</span> <span class="s1">&#39;wmc&#39;</span><span class="p">,</span>
                <span class="s1">&#39;init_params&#39;</span><span class="p">:</span> <span class="s1">&#39;wmc&#39;</span><span class="p">,</span>
            <span class="p">},</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">EventDetectorGMMdeprecated</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;gmm_deprecated&#39;</span>

    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">)</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="ne">DeprecationWarning</span><span class="p">)</span>
        <span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">mixture</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No hop length set.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Validation is not implemented for this learner.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="n">class_progress</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
            <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span>
            <span class="n">leave</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">desc</span><span class="o">=</span><span class="s1">&#39;           </span><span class="si">{0:&gt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Learn &#39;</span><span class="p">),</span>
            <span class="n">bar_format</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">{l_bar}{bar}</span><span class="s1">| </span><span class="si">{n_fmt}</span><span class="s1">/</span><span class="si">{total_fmt}</span><span class="s1">&#39;</span><span class="p">,</span>  <span class="c1"># [{elapsed}&lt;{remaining}, {rate_fmt}]&#39;,</span>
            <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">disable_progress_bar</span>
        <span class="p">)</span>

        <span class="c1"># Collect training examples</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">event_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">class_progress</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_progress</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{title:&lt;15s}</span><span class="s1"> [</span><span class="si">{item_id:d}</span><span class="s1">/</span><span class="si">{total:d}</span><span class="s1">] </span><span class="si">{event_label:&lt;15s}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">title</span><span class="o">=</span><span class="s1">&#39;Learn&#39;</span><span class="p">,</span>
                    <span class="n">item_id</span><span class="o">=</span><span class="n">event_id</span><span class="p">,</span>
                    <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span>
                    <span class="n">event_label</span><span class="o">=</span><span class="n">event_label</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="n">data_positive</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">data_negative</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">for</span> <span class="n">audio_filename</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">())):</span>
                <span class="n">activity_matrix</span> <span class="o">=</span> <span class="n">activity_matrix_dict</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span>

                <span class="n">positive_mask</span> <span class="o">=</span> <span class="n">activity_matrix</span><span class="p">[:,</span> <span class="n">event_id</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">bool</span><span class="p">)</span>
                <span class="c1"># Store positive examples</span>
                <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">positive_mask</span><span class="p">):</span>
                    <span class="n">data_positive</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">positive_mask</span><span class="p">,</span> <span class="p">:])</span>

                <span class="c1"># Store negative examples</span>
                <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="o">~</span><span class="n">positive_mask</span><span class="p">):</span>
                    <span class="n">data_negative</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">audio_filename</span><span class="p">]</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="o">~</span><span class="n">positive_mask</span><span class="p">,</span> <span class="p">:])</span>

            <span class="k">if</span> <span class="n">event_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">]:</span>
                <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;positive&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;negative&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>

            <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s1">&#39;positive&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                <span class="s1">&#39;negative&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
            <span class="p">}</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_positive</span><span class="p">):</span>
                <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mixture</span><span class="o">.</span><span class="n">GMM</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">data_positive</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_negative</span><span class="p">):</span>
                <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mixture</span><span class="o">.</span><span class="n">GMM</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">data_negative</span><span class="p">)</span>
                <span class="p">)</span>

    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>

        <span class="n">frame_probabilities_positive</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">frame_probabilities_negative</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">),</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">frame_probabilities_positive</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>
        <span class="n">frame_probabilities_negative</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

        <span class="k">for</span> <span class="n">event_id</span><span class="p">,</span> <span class="n">event_label</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]:</span>
                <span class="n">frame_probabilities_positive</span><span class="p">[</span><span class="n">event_id</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;positive&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">score_samples</span><span class="p">(</span>
                    <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]:</span>
                <span class="n">frame_probabilities_negative</span><span class="p">[</span><span class="n">event_id</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">][</span><span class="n">event_label</span><span class="p">][</span><span class="s1">&#39;negative&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">score_samples</span><span class="p">(</span>
                    <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">frame_probabilities_positive</span><span class="p">,</span> <span class="n">frame_probabilities_negative</span>


<div class="viewcode-block" id="EventDetectorMLP"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorMLP.html#dcase_framework.learners.EventDetectorMLP">[docs]</a><span class="k">class</span> <span class="nc">EventDetectorMLP</span><span class="p">(</span><span class="n">EventDetector</span><span class="p">,</span> <span class="n">KerasMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Simple MLP based sequential Keras model for Sound Event Detection&quot;&quot;&quot;</span>

<div class="viewcode-block" id="EventDetectorMLP.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorMLP.html#dcase_framework.learners.EventDetectorMLP.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">({</span>
            <span class="s1">&#39;win_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
            <span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
            <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="s1">&#39;mlp&#39;</span><span class="p">,</span>
            <span class="s1">&#39;scene_handling&#39;</span><span class="p">:</span> <span class="s1">&#39;scene-dependent&#39;</span><span class="p">,</span>
            <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;seed&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s1">&#39;keras&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;backend&#39;</span><span class="p">:</span> <span class="s1">&#39;theano&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;backend_parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                        <span class="s1">&#39;CNR&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                        <span class="s1">&#39;device&#39;</span><span class="p">:</span> <span class="s1">&#39;cpu&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;fastmath&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
                        <span class="s1">&#39;floatX&#39;</span><span class="p">:</span> <span class="s1">&#39;float64&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;openmp&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
                        <span class="s1">&#39;optimizer&#39;</span><span class="p">:</span> <span class="s1">&#39;None&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;threads&#39;</span><span class="p">:</span> <span class="mi">1</span>
                    <span class="p">}</span>
                <span class="p">},</span>
                <span class="s1">&#39;model&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">[</span>
                        <span class="p">{</span>
                            <span class="s1">&#39;class_name&#39;</span><span class="p">:</span> <span class="s1">&#39;Dense&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">{</span>
                                <span class="s1">&#39;activation&#39;</span><span class="p">:</span> <span class="s1">&#39;relu&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;kernel_initializer&#39;</span><span class="p">:</span> <span class="s1">&#39;uniform&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;units&#39;</span><span class="p">:</span> <span class="mi">50</span>
                            <span class="p">}</span>
                        <span class="p">},</span>
                        <span class="p">{</span>
                            <span class="s1">&#39;class_name&#39;</span><span class="p">:</span> <span class="s1">&#39;Dense&#39;</span><span class="p">,</span>
                            <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">{</span>
                                <span class="s1">&#39;activation&#39;</span><span class="p">:</span> <span class="s1">&#39;sigmoid&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;kernel_initializer&#39;</span><span class="p">:</span> <span class="s1">&#39;uniform&#39;</span><span class="p">,</span>
                                <span class="s1">&#39;units&#39;</span><span class="p">:</span> <span class="s1">&#39;CLASS_COUNT&#39;</span>
                            <span class="p">}</span>
                        <span class="p">}</span>
                    <span class="p">],</span>
                    <span class="s1">&#39;loss&#39;</span><span class="p">:</span> <span class="s1">&#39;categorical_crossentropy&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;metrics&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;categorical_accuracy&#39;</span><span class="p">],</span>
                    <span class="s1">&#39;optimizer&#39;</span><span class="p">:</span> <span class="p">{</span>
                        <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;Adam&#39;</span>
                    <span class="p">}</span>
                <span class="p">},</span>
                <span class="s1">&#39;training&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;batch_size&#39;</span><span class="p">:</span> <span class="mi">256</span><span class="p">,</span>
                    <span class="s1">&#39;epochs&#39;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
                    <span class="s1">&#39;shuffle&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                    <span class="s1">&#39;callbacks&#39;</span><span class="p">:</span> <span class="p">[],</span>
                <span class="p">},</span>
                <span class="s1">&#39;validation&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;enable&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
                    <span class="s1">&#39;setup_source&#39;</span><span class="p">:</span> <span class="s1">&#39;generated_scene_location_event_balanced&#39;</span><span class="p">,</span>
                    <span class="s1">&#39;validation_amount&#39;</span><span class="p">:</span> <span class="mf">0.1</span>
                <span class="p">}</span>
            <span class="p">},</span>
        <span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">override</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;params&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_parameters</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">EventDetectorMLP</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;mlp&#39;</span></div>

<div class="viewcode-block" id="EventDetectorMLP.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorMLP.learn.html#dcase_framework.learners.EventDetectorMLP.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">validation_files</span><span class="o">=</span><span class="p">[],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>
<span class="sd">        validation_files: list of filenames</span>
<span class="sd">            Predefined validation files, use parameter &#39;validation.setup_source=dataset&#39; to use them.</span>

<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Collect training files</span>
        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>

        <span class="c1"># Validation files</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;generated&#39;</span><span class="p">):</span>
                <span class="n">validation_files</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_generate_validation</span><span class="p">(</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">validation_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">,</span> <span class="s1">&#39;generated_scene_event_balanced&#39;</span><span class="p">),</span>
                    <span class="n">valid_percentage</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.validation_amount&#39;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">),</span>
                    <span class="n">seed</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.seed&#39;</span><span class="p">),</span>
                <span class="p">)</span>

            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;dataset&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                    <span class="n">validation_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">training_files</span><span class="p">)))</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No validation_files set&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                    <span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation.setup_source [</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span>
                <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Double check that training and validation files are not overlapping.</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">validation_files</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Training and validation file lists are overlapping!&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Convert annotations into activity matrix format</span>
        <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>

        <span class="c1"># Process data</span>
        <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">)</span>
        <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Training items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{examples:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">examples</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">X_training</span><span class="p">)))</span>

        <span class="c1"># Process validation data</span>
        <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
            <span class="n">X_validation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">)</span>
            <span class="n">Y_validation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span><span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">)</span>

            <span class="n">validation</span> <span class="o">=</span> <span class="p">(</span><span class="n">X_validation</span><span class="p">,</span> <span class="n">Y_validation</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Validation items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{validation:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">validation</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">X_validation</span><span class="p">)))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="c1"># Setup Keras</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_setup_keras</span><span class="p">()</span>

        <span class="k">with</span> <span class="n">SuppressStdoutAndStderr</span><span class="p">():</span>
            <span class="c1"># Import keras and suppress backend announcement printed to stderr</span>
            <span class="kn">import</span> <span class="nn">keras</span>

        <span class="c1"># Create model</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">create_model</span><span class="p">(</span><span class="n">input_shape</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_input_size</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_model_summary</span><span class="p">()</span>

        <span class="n">class_weight</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c1"># Special case with binary classifier</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.class_weight&#39;</span><span class="p">):</span>
                <span class="n">class_weight</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">class_id</span><span class="p">,</span> <span class="n">weight</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.class_weight&#39;</span><span class="p">)):</span>
                    <span class="n">class_weight</span><span class="p">[</span><span class="n">class_id</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">weight</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
                <span class="n">negative_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">positive_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Positives items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{positives:d}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{percentage:.2f}</span><span class="s1"> %)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">positives</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">),</span>
                    <span class="n">percentage</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span><span class="o">+</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">))</span><span class="o">*</span><span class="mi">100</span>
                <span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Negatives items </span><span class="se">\t</span><span class="s1">[</span><span class="si">{negatives:d}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{percentage:.2f}</span><span class="s1"> %)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">negatives</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">),</span>
                    <span class="n">percentage</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">)</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">))</span> <span class="o">*</span> <span class="mi">100</span>
                <span class="p">))</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Class weights </span><span class="se">\t</span><span class="s1">[</span><span class="si">{weights}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">weights</span><span class="o">=</span><span class="n">class_weight</span><span class="p">))</span>

        <span class="n">callback_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_callback_list</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Feature vector </span><span class="se">\t</span><span class="s1">[</span><span class="si">{vector:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">vector</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_input_size</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Batch size </span><span class="se">\t</span><span class="s1">[</span><span class="si">{batch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">batch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epochs </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{epoch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
            <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
            <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
            <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
            <span class="n">epochs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
            <span class="n">validation_data</span><span class="o">=</span><span class="n">validation</span><span class="p">,</span>
            <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
            <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
            <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span><span class="p">,</span>
            <span class="n">class_weight</span><span class="o">=</span><span class="n">class_weight</span>
        <span class="p">)</span>

        <span class="c1"># Manually update callbacks</span>
        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">StasherCallback</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
                <span class="n">best_weights</span> <span class="o">=</span> <span class="n">callback</span><span class="o">.</span><span class="n">get_best</span><span class="p">()[</span><span class="s1">&#39;weights&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">best_weights</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">set_weights</span><span class="p">(</span><span class="n">best_weights</span><span class="p">)</span>
                <span class="k">break</span>

        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;learning_history&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span></div>

<div class="viewcode-block" id="EventDetectorMLP.predict"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorMLP.predict.html#dcase_framework.learners.EventDetectorMLP.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="n">FeatureContainer</span><span class="p">):</span>
            <span class="n">feature_data</span> <span class="o">=</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span></div></div>


<div class="viewcode-block" id="EventDetectorKerasSequential"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.html#dcase_framework.learners.EventDetectorKerasSequential">[docs]</a><span class="k">class</span> <span class="nc">EventDetectorKerasSequential</span><span class="p">(</span><span class="n">EventDetectorMLP</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sequential Keras model for Sound Event Detection&quot;&quot;&quot;</span>

<div class="viewcode-block" id="EventDetectorKerasSequential.__init__"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.html#dcase_framework.learners.EventDetectorKerasSequential.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">EventDetectorKerasSequential</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="s1">&#39;keras_seq&#39;</span>

        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;training_data_processor&#39;</span><span class="p">,</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_generators&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">data_generator_list</span> <span class="o">=</span> <span class="n">get_class_inheritors</span><span class="p">(</span><span class="n">BaseDataGenerator</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">data_generator_item</span> <span class="ow">in</span> <span class="n">data_generator_list</span><span class="p">:</span>
                <span class="n">generator</span> <span class="o">=</span> <span class="n">data_generator_item</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">generator</span><span class="o">.</span><span class="n">method</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="n">generator</span><span class="o">.</span><span class="n">method</span><span class="p">]</span> <span class="o">=</span> <span class="n">data_generator_item</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">data_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature processing chain</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">         feature_processing_chain</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@data_processor</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">data_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">data_processor_training</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Feature processing chain</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">         feature_processing_chain</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="nd">@data_processor_training</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">data_processor_training</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;data_processor_training&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="EventDetectorKerasSequential.learn"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.learn.html#dcase_framework.learners.EventDetectorKerasSequential.learn">[docs]</a>    <span class="k">def</span> <span class="nf">learn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">annotations</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">data_filenames</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">validation_files</span><span class="o">=</span><span class="p">[],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Learn based on data and annotations</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        data : dict of FeatureContainers</span>
<span class="sd">            Feature data</span>
<span class="sd">        annotations : dict of MetadataContainers</span>
<span class="sd">            Meta data</span>
<span class="sd">        data_filenames : dict of filenames</span>
<span class="sd">            Filenames of stored data</span>
<span class="sd">        validation_files: list of filenames</span>
<span class="sd">            Predefined validation files, use parameter &#39;validation.setup_source=dataset&#39; to use them.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifting.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
           <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
           <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)):</span>

            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Temporal shifting cannot be used. Use epoch_processing or generator to allow temporal &#39;</span> \
                      <span class="s1">&#39;shifting of data.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                      <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Collect training files</span>
        <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">annotations</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>

        <span class="c1"># Validation files</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;generated&#39;</span><span class="p">):</span>
                <span class="n">validation_files</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_generate_validation</span><span class="p">(</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">validation_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">,</span> <span class="s1">&#39;generated_scene_event_balanced&#39;</span><span class="p">),</span>
                    <span class="n">valid_percentage</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.validation_amount&#39;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">),</span>
                    <span class="n">seed</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.seed&#39;</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;dataset&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                    <span class="n">validation_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">training_files</span><span class="p">)))</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: No validation_files set&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
                    <span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Unknown validation.setup_source [</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.setup_source&#39;</span><span class="p">)</span>
                <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">training_files</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">validation_files</span><span class="p">)))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">validation_files</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Double check that training and validation files are not overlapping.</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">training_files</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">validation_files</span><span class="p">):</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Training and validation file lists are overlapping!&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
            <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="c1"># Setup Keras</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_setup_keras</span><span class="p">()</span>

        <span class="k">with</span> <span class="n">SuppressStdoutAndStderr</span><span class="p">():</span>
            <span class="c1"># Import keras and suppress backend announcement printed to stderr</span>
            <span class="kn">import</span> <span class="nn">keras</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
            <span class="c1"># Create generators</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">:</span>
                <span class="n">training_data_generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)](</span>
                    <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                    <span class="n">data_filenames</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">,</span>
                    <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                    <span class="n">data_processor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_processor_training</span><span class="p">,</span>
                    <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                    <span class="n">hop_length_seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">),</span>
                    <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                    <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">data_refresh_on_each_epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifting.enable&#39;</span><span class="p">),</span>
                    <span class="n">label_mode</span><span class="o">=</span><span class="s1">&#39;event&#39;</span><span class="p">,</span>
                    <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.parameters&#39;</span><span class="p">,</span> <span class="p">{})</span>
                <span class="p">)</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
                    <span class="n">validation_data_generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_generators</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)](</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">data_filenames</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">,</span>
                        <span class="n">annotations</span><span class="o">=</span><span class="n">annotations</span><span class="p">,</span>
                        <span class="n">data_processor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="p">,</span>
                        <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">,</span>
                        <span class="n">hop_length_seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">),</span>
                        <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                        <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">label_mode</span><span class="o">=</span><span class="s1">&#39;event&#39;</span><span class="p">,</span>
                        <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.parameters&#39;</span><span class="p">,</span> <span class="p">{})</span>
                    <span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">validation_data_generator</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Generator method not implemented [</span><span class="si">{method}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                    <span class="n">method</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.method&#39;</span><span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

            <span class="n">input_shape</span> <span class="o">=</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">input_size</span>
            <span class="n">training_data_size</span> <span class="o">=</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">data_size</span>
            <span class="k">if</span> <span class="n">validation_data_generator</span><span class="p">:</span>
                <span class="n">validation_data_size</span> <span class="o">=</span> <span class="n">validation_data_generator</span><span class="o">.</span><span class="n">data_size</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Convert annotations into activity matrix format</span>
            <span class="n">activity_matrix_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_target_matrix_dict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">annotations</span><span class="p">)</span>

            <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
            <span class="p">)</span>

            <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                <span class="n">validation_data</span> <span class="o">=</span> <span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                        <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;default&#39;</span>
                    <span class="p">),</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                        <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                        <span class="n">files</span><span class="o">=</span><span class="n">validation_files</span><span class="p">,</span>
                        <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;default&#39;</span>
                    <span class="p">)</span>
                <span class="p">)</span>

                <span class="n">validation_data_size</span> <span class="o">=</span> <span class="n">validation_data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

            <span class="n">input_shape</span> <span class="o">=</span> <span class="n">X_training</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">training_data_size</span> <span class="o">=</span> <span class="n">X_training</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Create model</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">create_model</span><span class="p">(</span><span class="n">input_shape</span><span class="o">=</span><span class="n">input_shape</span><span class="p">)</span>

        <span class="c1"># Get processing interval</span>
        <span class="n">processing_interval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_processing_interval</span><span class="p">()</span>

        <span class="c1"># Create callbacks</span>
        <span class="n">callback_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_callback_list</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_model_summary</span><span class="p">()</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Files&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span>
                <span class="s1">&#39;    Training </span><span class="se">\t</span><span class="s1">[</span><span class="si">{examples:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">examples</span><span class="o">=</span><span class="n">training_data_size</span><span class="p">)</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="n">validation_files</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span>
                    <span class="s1">&#39;    Validation </span><span class="se">\t</span><span class="s1">[</span><span class="si">{validation:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">validation</span><span class="o">=</span><span class="n">validation_data_size</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

        <span class="n">class_weight</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c1"># Special case with binary classifier</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.class_weight&#39;</span><span class="p">):</span>
                <span class="n">class_weight</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">class_id</span><span class="p">,</span> <span class="n">weight</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.class_weight&#39;</span><span class="p">)):</span>
                    <span class="n">class_weight</span><span class="p">[</span><span class="n">class_id</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">weight</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">Y_training</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">negative_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">positive_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">Y_training</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">negative_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">positive_examples_id</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">Y_training</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Items&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Positive </span><span class="se">\t</span><span class="s1">[</span><span class="si">{perc:.2f}</span><span class="s1"> %]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{positives:d}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">positives</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">),</span>
                    <span class="n">perc</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span><span class="o">+</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">))</span><span class="o">*</span><span class="mi">100</span>
                <span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Negative </span><span class="se">\t</span><span class="s1">[</span><span class="si">{perc:.2f}</span><span class="s1"> %]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{negatives:d}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">negatives</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">),</span>
                    <span class="n">perc</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">)</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">positive_examples_id</span><span class="p">)</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">negative_examples_id</span><span class="p">))</span> <span class="o">*</span> <span class="mi">100</span>
                <span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Class weights </span><span class="se">\t</span><span class="s1">[</span><span class="si">{weights}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">weights</span><span class="o">=</span><span class="n">class_weight</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_extra_debug</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Input&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Feature vector </span><span class="se">\t</span><span class="s1">[</span><span class="si">{vector:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">vector</span><span class="o">=</span><span class="n">input_shape</span><span class="p">)</span>
            <span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.enable&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Sequence</span><span class="se">\t</span><span class="s1">[</span><span class="si">{length:d}</span><span class="s1">]</span><span class="se">\t\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">length</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.frames&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;input_sequencer.frames&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)):</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Sequence shifting per epoch&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Shift </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{step:d}</span><span class="s1"> per epoch]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">step</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.step&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.step&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Max </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{max:d}</span><span class="s1"> per epoch]</span><span class="se">\t</span><span class="s1">(</span><span class="si">{time:4.2f}</span><span class="s1"> sec)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="nb">max</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.max&#39;</span><span class="p">),</span>
                    <span class="n">time</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.max&#39;</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Border </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{border:s}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">border</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.border&#39;</span><span class="p">,</span> <span class="s1">&#39;roll&#39;</span><span class="p">)</span>
                <span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Batch size </span><span class="se">\t</span><span class="s1">[</span><span class="si">{batch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">batch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epochs </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{epoch:d}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">epoch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="c1"># Extra info about training</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">training_data_generator</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">training_data_generator</span><span class="o">.</span><span class="n">info</span><span class="p">():</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epoch processing </span><span class="se">\t</span><span class="s1">[</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;Epoch-by-Epoch&#39;</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  Epoch processing </span><span class="se">\t</span><span class="s1">[</span><span class="si">{mode}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;Keras&#39;</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
               <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.enable&#39;</span><span class="p">)):</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  External metrics&#39;</span><span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Metrics</span><span class="se">\t\t</span><span class="s1">Label</span><span class="se">\t</span><span class="s1">Evaluator:Name&#39;</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.metrics&#39;</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    </span><span class="se">\t\t</span><span class="s1">[</span><span class="si">{label}</span><span class="s1">]</span><span class="se">\t</span><span class="s1">[</span><span class="si">{metric}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">label</span><span class="o">=</span><span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;label&#39;</span><span class="p">),</span>
                        <span class="n">metric</span><span class="o">=</span><span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;evaluator&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;:&#39;</span> <span class="o">+</span> <span class="n">metric</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">))</span>
                    <span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    Interval </span><span class="se">\t</span><span class="s1">[</span><span class="si">{processing_interval:d}</span><span class="s1"> epochs]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">processing_interval</span><span class="o">=</span><span class="n">processing_interval</span><span class="p">)</span>
                <span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="p">)</span>

        <span class="c1"># Set seed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_seed</span><span class="p">()</span>

        <span class="n">epochs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epochs&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

        <span class="c1"># Initialize training history</span>
        <span class="n">learning_history</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;loss&#39;</span><span class="p">:</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,)),</span>
            <span class="s1">&#39;val_loss&#39;</span><span class="p">:</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,)),</span>
        <span class="p">}</span>
        <span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">metrics</span><span class="p">:</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="n">metric</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="s1">&#39;val_&#39;</span><span class="o">+</span><span class="n">metric</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
        <span class="k">for</span> <span class="n">quantity</span> <span class="ow">in</span> <span class="n">learning_history</span><span class="p">:</span>
            <span class="n">learning_history</span><span class="p">[</span><span class="n">quantity</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.enable&#39;</span><span class="p">):</span>
            <span class="c1"># Get external metric evaluators</span>
            <span class="n">external_metric_evaluators</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_external_metric_evaluators</span><span class="p">()</span>

            <span class="k">for</span> <span class="n">external_metric_id</span> <span class="ow">in</span> <span class="n">external_metric_evaluators</span><span class="p">:</span>
                <span class="n">metric_label</span> <span class="o">=</span> <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;label&#39;</span><span class="p">]</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">epochs</span><span class="p">,))</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">nan</span>

            <span class="k">for</span> <span class="n">epoch_start</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">processing_interval</span><span class="p">):</span>
                <span class="c1"># Last epoch</span>
                <span class="n">epoch_end</span> <span class="o">=</span> <span class="n">epoch_start</span> <span class="o">+</span> <span class="n">processing_interval</span>
                <span class="c1"># Make sure we have only specified amount of epochs</span>
                <span class="k">if</span> <span class="n">epoch_end</span> <span class="o">&gt;</span> <span class="n">epochs</span><span class="p">:</span>
                    <span class="n">epoch_end</span> <span class="o">=</span> <span class="n">epochs</span>

                <span class="c1"># Model fitting</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                    <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit_generator</span><span class="p">(</span>
                        <span class="n">generator</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                        <span class="n">steps_per_epoch</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                        <span class="n">initial_epoch</span><span class="o">=</span><span class="n">epoch_start</span><span class="p">,</span>
                        <span class="n">epochs</span><span class="o">=</span><span class="n">epoch_end</span><span class="p">,</span>
                        <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                        <span class="n">validation_steps</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                        <span class="n">max_queue_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.max_q_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">workers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.workers&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                        <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span><span class="p">,</span>
                        <span class="n">class_weight</span><span class="o">=</span><span class="n">class_weight</span>
                    <span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                        <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
                        <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
                        <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                        <span class="n">initial_epoch</span><span class="o">=</span><span class="n">epoch_start</span><span class="p">,</span>
                        <span class="n">epochs</span><span class="o">=</span><span class="n">epoch_end</span><span class="p">,</span>
                        <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data</span><span class="p">,</span>
                        <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                        <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                        <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span><span class="p">,</span>
                        <span class="n">class_weight</span><span class="o">=</span><span class="n">class_weight</span>
                    <span class="p">)</span>

                <span class="c1"># Store keras metrics into learning history log</span>
                <span class="k">for</span> <span class="n">keras_metric</span> <span class="ow">in</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">:</span>
                    <span class="n">learning_history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">][</span><span class="n">epoch_start</span><span class="p">:</span><span class="n">epoch_start</span><span class="o">+</span><span class="nb">len</span><span class="p">(</span><span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">])]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">]</span>

                <span class="c1"># Evaluate validation data with external metrics</span>
                <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;validation.enable&#39;</span><span class="p">)</span> <span class="ow">and</span>
                   <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.external_metrics.enable&#39;</span><span class="p">)):</span>

                    <span class="c1"># Recognizer class</span>
                    <span class="n">recognizer</span> <span class="o">=</span> <span class="n">EventRecognizer</span><span class="p">(</span>
                        <span class="n">hop_length_seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;hop_length_seconds&#39;</span><span class="p">),</span>
                        <span class="n">params</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.epoch_processing.recognizer&#39;</span><span class="p">),</span>
                        <span class="n">class_labels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">class_labels</span>
                    <span class="p">)</span>

                    <span class="k">for</span> <span class="n">external_metric_id</span> <span class="ow">in</span> <span class="n">external_metric_evaluators</span><span class="p">:</span>
                        <span class="c1"># Reset evaluators</span>
                        <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>

                        <span class="n">metric_label</span> <span class="o">=</span> <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;label&#39;</span><span class="p">]</span>

                        <span class="c1"># Evaluate validation data</span>
                        <span class="k">for</span> <span class="n">validation_file</span> <span class="ow">in</span> <span class="n">validation_files</span><span class="p">:</span>
                            <span class="c1"># Get feature data</span>
                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                                <span class="n">feature_data</span><span class="p">,</span> <span class="n">feature_data_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="o">.</span><span class="n">load</span><span class="p">(</span>
                                    <span class="n">feature_filename_dict</span><span class="o">=</span><span class="n">data_filenames</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]</span>
                                <span class="p">)</span>

                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">feature_data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]</span>

                            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">feature_data</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span>

                            <span class="c1"># Predict</span>
                            <span class="n">predicted</span> <span class="o">=</span> <span class="n">recognizer</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">frame_probabilities</span><span class="o">=</span><span class="n">frame_probabilities</span><span class="p">)</span>

                            <span class="c1"># Get reference data</span>
                            <span class="n">meta</span> <span class="o">=</span> <span class="p">[]</span>
                            <span class="k">for</span> <span class="n">meta_item</span> <span class="ow">in</span> <span class="n">annotations</span><span class="p">[</span><span class="n">validation_file</span><span class="p">]:</span>
                                <span class="k">if</span> <span class="s1">&#39;event_label&#39;</span> <span class="ow">in</span> <span class="n">meta_item</span> <span class="ow">and</span> <span class="n">meta_item</span><span class="o">.</span><span class="n">event_label</span><span class="p">:</span>
                                    <span class="n">meta</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">meta_item</span><span class="p">)</span>

                            <span class="c1"># Evaluate</span>
                            <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">evaluate</span><span class="p">(</span>
                                <span class="n">reference_event_list</span><span class="o">=</span><span class="n">meta</span><span class="p">,</span>
                                <span class="n">estimated_event_list</span><span class="o">=</span><span class="n">predicted</span>
                            <span class="p">)</span>

                        <span class="c1"># Get metric value</span>
                        <span class="n">metric_value</span> <span class="o">=</span> <span class="n">DottedDict</span><span class="p">(</span>
                            <span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">results</span><span class="p">()</span>
                        <span class="p">)</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;path&#39;</span><span class="p">])</span>

                        <span class="k">if</span> <span class="n">metric_value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                            <span class="n">message</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{name}</span><span class="s1">: Metric was not found, evaluator:[</span><span class="si">{evaluator}</span><span class="s1">] metric:[</span><span class="si">{metric}</span><span class="s1">]&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                                <span class="n">evaluator</span><span class="o">=</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;evaluator&#39;</span><span class="p">],</span>
                                <span class="n">metric</span><span class="o">=</span><span class="n">external_metric_evaluators</span><span class="p">[</span><span class="n">external_metric_id</span><span class="p">][</span><span class="s1">&#39;path&#39;</span><span class="p">]</span>
                            <span class="p">)</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
                            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

                        <span class="c1"># Inject external metric values to the callbacks</span>
                        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;set_external_metric_value&#39;</span><span class="p">):</span>
                                <span class="n">callback</span><span class="o">.</span><span class="n">set_external_metric_value</span><span class="p">(</span>
                                    <span class="n">metric_label</span><span class="o">=</span><span class="n">metric_label</span><span class="p">,</span>
                                    <span class="n">metric_value</span><span class="o">=</span><span class="n">metric_value</span>
                                <span class="p">)</span>

                        <span class="c1"># Store metric value into learning history log</span>
                        <span class="n">learning_history</span><span class="p">[</span><span class="n">metric_label</span><span class="p">][</span><span class="n">epoch_end</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">metric_value</span>

                <span class="c1"># Manually update callbacks</span>
                <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;update&#39;</span><span class="p">):</span>
                        <span class="n">callback</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>

                <span class="c1"># Check we need to stop training</span>
                <span class="n">stop_training</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;stop&#39;</span><span class="p">):</span>
                        <span class="k">if</span> <span class="n">callback</span><span class="o">.</span><span class="n">stop</span><span class="p">():</span>
                            <span class="n">stop_training</span> <span class="o">=</span> <span class="kc">True</span>

                <span class="k">if</span> <span class="n">stop_training</span><span class="p">:</span>
                    <span class="c1"># Stop the training loop</span>
                    <span class="k">break</span>

                <span class="c1"># Training data processing between epochs</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;temporal_shifter.enable&#39;</span><span class="p">):</span>
                    <span class="c1"># Increase temporal shifting</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_processor_training</span><span class="o">.</span><span class="n">call_method</span><span class="p">(</span><span class="s1">&#39;increase_shifting&#39;</span><span class="p">)</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                        <span class="c1"># Refresh training data manually with new parameters</span>
                        <span class="n">X_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_data</span><span class="p">(</span>
                            <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                            <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                            <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
                        <span class="p">)</span>
                        <span class="n">Y_training</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepare_activity</span><span class="p">(</span>
                            <span class="n">activity_matrix_dict</span><span class="o">=</span><span class="n">activity_matrix_dict</span><span class="p">,</span>
                            <span class="n">files</span><span class="o">=</span><span class="n">training_files</span><span class="p">,</span>
                            <span class="n">processor</span><span class="o">=</span><span class="s1">&#39;training&#39;</span>
                        <span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.enable&#39;</span><span class="p">):</span>
                <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit_generator</span><span class="p">(</span>
                    <span class="n">generator</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                    <span class="n">steps_per_epoch</span><span class="o">=</span><span class="n">training_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                    <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span>
                    <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">generator</span><span class="p">(),</span>
                    <span class="n">validation_steps</span><span class="o">=</span><span class="n">validation_data_generator</span><span class="o">.</span><span class="n">steps_count</span><span class="p">,</span>
                    <span class="n">max_queue_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;generator.max_q_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">workers</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span><span class="p">,</span>
                    <span class="n">class_weight</span><span class="o">=</span><span class="n">class_weight</span>
                <span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">hist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span>
                    <span class="n">x</span><span class="o">=</span><span class="n">X_training</span><span class="p">,</span>
                    <span class="n">y</span><span class="o">=</span><span class="n">Y_training</span><span class="p">,</span>
                    <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.batch_size&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                    <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span>
                    <span class="n">validation_data</span><span class="o">=</span><span class="n">validation_data</span><span class="p">,</span>
                    <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">shuffle</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">learner_params</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s1">&#39;training.shuffle&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                    <span class="n">callbacks</span><span class="o">=</span><span class="n">callback_list</span><span class="p">,</span>
                    <span class="n">class_weight</span><span class="o">=</span><span class="n">class_weight</span>
                <span class="p">)</span>

            <span class="c1"># Store keras metrics into learning history log</span>
            <span class="k">for</span> <span class="n">keras_metric</span> <span class="ow">in</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">:</span>
                <span class="n">learning_history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">])]</span> <span class="o">=</span> <span class="n">hist</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="n">keras_metric</span><span class="p">]</span>

        <span class="c1"># Manually update callbacks</span>
        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">callback</span> <span class="ow">in</span> <span class="n">callback_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">StasherCallback</span><span class="p">):</span>
                <span class="n">callback</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
                <span class="n">best_weights</span> <span class="o">=</span> <span class="n">callback</span><span class="o">.</span><span class="n">get_best</span><span class="p">()[</span><span class="s1">&#39;weights&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">best_weights</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">set_weights</span><span class="p">(</span><span class="n">best_weights</span><span class="p">)</span>
                <span class="k">break</span>

        <span class="c1"># Store learning history to the model</span>
        <span class="bp">self</span><span class="p">[</span><span class="s1">&#39;learning_history&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">learning_history</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="EventDetectorKerasSequential.predict"><a class="viewcode-back" href="../../generated/dcase_framework.learners.EventDetectorKerasSequential.predict.html#dcase_framework.learners.EventDetectorKerasSequential.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feature_data</span><span class="p">):</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="n">FeatureContainer</span><span class="p">):</span>
            <span class="n">feature_data</span> <span class="o">=</span> <span class="n">feature_data</span><span class="o">.</span><span class="n">feat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">feature_data</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="p">:</span>
            <span class="c1"># Feature repository given, and feature processor present</span>
            <span class="n">feature_data</span><span class="p">,</span> <span class="n">feature_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_processor</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">feature_data</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span>

        <span class="c1"># Frame probabilities</span>
        <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">feature_data</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">4</span><span class="p">:</span>
                <span class="c1"># Still feature data in wrong shape, trying to recover</span>
                <span class="n">data_sequencer</span> <span class="o">=</span> <span class="n">DataSequencer</span><span class="p">(</span>
                    <span class="n">frames</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                    <span class="n">hop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">input_shape</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                <span class="p">)</span>
                <span class="n">feature_data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">expand_dims</span><span class="p">(</span><span class="n">data_sequencer</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">feature_data</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">feature_data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

            <span class="c1"># Join sequences</span>
            <span class="c1"># TODO: if data_sequencer.hop != data_sequencer.frames, do additional processing here.</span>
            <span class="n">frame_probabilities</span> <span class="o">=</span> <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span>
                <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">frame_probabilities</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="p">)</span>

        <span class="k">return</span> <span class="n">frame_probabilities</span></div></div>

</pre></div>

           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Toni Heittola et al..

    </p>
  </div> 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>